Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2010-02-23 : 21:08:44
|
| select ----from ---where condition1 , condtion2,...I want to select based on @param. Current statement is as above.Select all records Select the records where tbl1.col1 is not null if @param is not nullThanks. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-02-23 : 21:14:56
|
[code]select *from sometablewhere ( @param is null or somecol = @param )[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2010-02-23 : 21:23:17
|
I just want to use @param as flag. If it is not null [true] i will select records where col1 is not null. Otherwise, I will select records and not checking col1 .quote: Originally posted by khtan
select *from sometablewhere ( @param is null or somecol = @param ) KH[spoiler]Time is always against us[/spoiler]
|
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-02-23 : 21:32:21
|
[code]select *from sometablewhere ( @param is null or somecol = @param (@param is not null and col1 is not null) )[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-24 : 10:06:50
|
quote: Originally posted by khtan
select *from sometablewhere ( @param is null or somecol = @param (@param is not null and col1 is not null) ) KH[spoiler]Time is always against us[/spoiler]
can be reduced as select *from sometablewhere ( @param is null or col1 is not null ) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|