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 |
albertkohl
Aged Yak Warrior
740 Posts |
Posted - 2008-09-19 : 14:26:32
|
hey, i want to write a select query, that basically checks a field, if that field is empty, then it does one thing, if it's not, it does another... here's what i tried, but i get syntax errors... can u guys give me a hand?select per1_fname,per1_lname,name,address1,address2,city, state_abbrv,zip,phoneinto #workfrom test.dbo.condnc cwhere (if dispo2= ' ' dispo1='1') (if dispo2<>' ' dispo2='1')go do know if this is something i can do, or if i'm just being a nub... thanks! |
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-09-19 : 14:34:30
|
Here's one way:where 1 = case when dispo2 != ' ' then dispo2 else dispo1 endBe One with the OptimizerTG |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-19 : 14:34:46
|
do like below:-select per1_fname,per1_lname,name,address1,address2,city, state_abbrv,zip,phoneinto #workfrom test.dbo.condnc cwhere coalesce(nullif(dispo2,' '),dispo1)='1' |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
|
jp2code
Posting Yak Master
175 Posts |
Posted - 2008-09-19 : 17:57:54
|
Jeff,I like that boolean logic.I wonder: Is there a way to use it in this situation?SELECT Serial_Number AS 'SN', CASE WHEN CoilType is NULL Then ' ' Else CoilType END AS 'CoilType', Op_ID AS 'OperatorID', System_ID AS 'SystemID', FROM dbo.PartsWHERE ([Serial_Number] Like '%' + @SN + '%') Avoid Sears Home Improvement |
|
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2008-09-19 : 20:42:12
|
What are you talking about? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-20 : 01:31:57
|
quote: Originally posted by jp2code Jeff,I like that boolean logic.I wonder: Is there a way to use it in this situation?SELECT Serial_Number AS 'SN', CASE WHEN CoilType is NULL Then ' ' Else CoilType END AS 'CoilType', Op_ID AS 'OperatorID', System_ID AS 'SystemID', FROM dbo.PartsWHERE ([Serial_Number] Like '%' + @SN + '%') Avoid Sears Home Improvement
didnt understand what condition you're trying to apply boolean logic. here you have only a single WHERE condition. |
|
|
|
|
|
|
|