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 |
|
kannis1
Starting Member
4 Posts |
Posted - 2006-07-03 : 00:33:22
|
| I'm having a problem with the following stored procedure. All I want to do is check if specialtyId is null. If it is, run the first query, if not run the second. The first one won't run if I pass it a null value. What am I doing wrong?CREATE Proc as_getCounselorBy_SpecialtyId @SpecialtyId int = nullASBeginif @SpecialtyId = null Select * from awCounselor where counselorId In (Select counselorId from awCoachSchedule) and activityStatus =1 order by signUpdate DESCelse Select * From awCounselor a (noLock) Join awCounselorSpecialty b (noLock) On a.counselorId = b.counselorId Where b.specialtyId = @SpecialtyId And a.activityStatus = 1 Order by signUpdate DescEndGO |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-07-03 : 00:46:06
|
You have to use IS NULLif @SpecialtyId IS null KH |
 |
|
|
kannis1
Starting Member
4 Posts |
Posted - 2006-07-03 : 00:58:10
|
| That did it, thanks! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-07-03 : 02:36:58
|
| As NULL cant be compared with any value, you need to use IS in place of =MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|