NULL Conditons in SQL Server -
this question has answer here:
- conditional conditons in sql server 2 answers
i have table this:
id | code | year --------+---------+---------- 0 | 1 | '1998' 1 | 5 | null 2 | 7 | '2013' 3 | 1 | '1892' 4 | 5 | null 5 | 7 | '1900'
i have combobox 3 values: all
, nulls
, not nulls
.
all
: load rows , no condition.
select * tbl_location
nulls
:
select * tbl_location year null
'not nulls'
select * tbl_location year not null
'all' combo-box value load rows without condition
i want in 1 query. can do?
you need pass value of combobox in @status
:
here need set conditions this:
declare @status varchar(15) --set status select * tbl_location (@status = 'all' or (@status = 'nulls' , year null) or (@status = 'not nulls' , year not null) )
Comments
Post a Comment