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 |
|
CVDpr
Starting Member
41 Posts |
Posted - 2009-06-09 : 11:16:00
|
| select CompanyId, FacilityId, InsId from myTbale where CompanyId = @CompanyId and FacilityId = @FacilityId and (InsId = @insId or @insId = -1)How i do the (InsId = @insId or @insId = -1)but using between, Thanks. |
|
|
asgast
Posting Yak Master
149 Posts |
Posted - 2009-06-09 : 12:09:01
|
| you don'tcurrently in the code you check insid for 2 possible values @insID and -1using between you would be checking for a range of values, query would return different resultstry WHERE InsId BETWEEN -1 AND @insID if you want to check the range |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-09 : 12:17:24
|
quote: Originally posted by asgast you don'tcurrently in the code you check insid for 2 possible values @insID and -1using between you would be checking for a range of values, query would return different resultstry WHERE InsId BETWEEN -1 AND @insID if you want to check the range
but this wont be equivalent to code that OP posted |
 |
|
|
CVDpr
Starting Member
41 Posts |
Posted - 2009-06-09 : 13:57:42
|
| thats the problem, i want if the variable @InsID1=-1, and @InsId2=-1 = show all the records elsedo the between @InsId1 and @InsId2.:-( |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-09 : 14:00:45
|
aha..where does this @InsID2 come from? in that case it should beselect CompanyId, FacilityId, InsId from myTbale where CompanyId = @CompanyId and FacilityId = @FacilityId and ((@InsID1=-1 and @InsId2=-1) or (InsId BETWEEN @InsID1 AND @InsID2)) |
 |
|
|
CVDpr
Starting Member
41 Posts |
Posted - 2009-06-09 : 14:22:09
|
| Yes, that work thanks. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-09 : 14:27:40
|
| welcome |
 |
|
|
|
|
|