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 |
|
raysefo
Constraint Violating Yak Guru
260 Posts |
Posted - 2007-01-19 : 16:23:20
|
| Hi,I have a SQL statement. In the where clause, if user selects a choice from dropdown list box and integer comes....where deptid = 1...but if user does NOT select a choice then i want to use a command (if there is) to get any deptid....where deptid = any...Any suggestions? |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-19 : 16:27:50
|
| Assuming NO department selected throws a value of 0 to the variable,select * from whatever where @variable in (0, deptid)Peter LarssonHelsingborg, Sweden |
 |
|
|
raysefo
Constraint Violating Yak Guru
260 Posts |
Posted - 2007-01-19 : 16:34:02
|
| i may misguided you. What i wanna do is, if no id is selected from dropdown, to get all deptartments. select deptpropertiesfrom mytableswhere deptid = (here i wanna put something in order to get all department properties!) |
 |
|
|
Jeff Moden
Aged Yak Warrior
652 Posts |
Posted - 2007-01-19 : 20:05:31
|
| I like Peter's method, but here's another...WHERE DeptID = CASE WHEN @DeptID IS NULL THEN DeptID ELSE @DeptID END--Jeff Moden |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-01-20 : 00:32:17
|
if no id is selected from dropdown then set @DeptID to NULLwhere DeptID = coalesce(@DeptID, DeptID) KH |
 |
|
|
|
|
|