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 |
|
kiri
Starting Member
38 Posts |
Posted - 2008-02-05 : 16:45:27
|
| i have one condition in where clause likewhere A.SOURCE IN ('PAR/CH/TEA','LATINO/PTC','LATINOS-B','LATINOS-E','LATINOS-S','LATINS/PTC','LATINB/PTC')instead of where clause i have to use in condition - using if or casestatement..i want like this:-source = case sourceid when o then '' when 1 then ('PAR/CH/TEA','LATINO/PTC','LATINOS-B','LATINOS-E','LATINOS-S','LATINS/PTC','LATINB/PTC')i can't use like IN statement in case-when and then...it gives me error so can u tell me correct solution plz..thanks |
|
|
jdaman
Constraint Violating Yak Guru
354 Posts |
Posted - 2008-02-05 : 17:06:46
|
| If im understanding you correctly you want to have a dynamic WHERE clause where depending on the value in sourceid it will filter records by varying criteria. You can do this by using an OR statement.where sourceid = 0 and source = ''or sourceid = 1 and source IN ('PAR/CH/TEA','LATINO/PTC','LATINOS-B','LATINOS-E','LATINOS-S','LATINS/PTC','LATINB/PTC') |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2008-02-05 : 17:28:59
|
| be sure to add parenthesis to the right palces since AND has priority over ORcond1 AND cond2 OR cond3 is different thancond1 AND (cond2 OR cond3)_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com <- new version out |
 |
|
|
|
|
|
|
|