LoginSignup
0
1

More than 1 year has passed since last update.

入力された項目のみ抽出条件に使用する。

Last updated at Posted at 2020-08-25

想定されるケース

一覧画面で検索用項目が複数あるが、値が入力された項目についてのみ検索条件で使用されるようにしたい。

検索項目が以下の3つの場合
・商品名
・値段
・ブランド名
以下のようにORをうまく利用することで、検索項目がnullでないときにのみ名称一致で検索できます。

select.sql
select ProductName, /* 商品名 */
       Price,       /* 値段 */
       BrandName    /* ブランド名 */
from TABLE 
where ([商品名] is null OR ([商品名] is not null AND ProductName = [商品名])
  and ([値段] is null OR ([値段] is not null AND Price = [値段])
  and ([ブランド名] is null OR ([ブランド名] is not null AND BrandName = [ブランド名])
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1