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 |
|
hrishy
Starting Member
47 Posts |
Posted - 2008-05-04 : 07:41:13
|
HiI have a column of datatype bit.When i run a case statement i get a error.SELECT Name,Married =CASE Married WHEN Married = '1'THEN 'Y' WHEN Married = '0' THEN 'N' ELSE NULL END,LastNamefrom Person The above code gives a error message Msg 102, Level 15, State 1, Line 3Incorrect syntax near '='.regardsHrishy |
|
|
ayamas
Aged Yak Warrior
552 Posts |
Posted - 2008-05-04 : 09:26:57
|
| Try thisSELECT Name,Married =CASE Married WHEN 1 THEN 'Y' WHEN 0 THEN 'N' ELSE NULL END,LastNamefrom Person |
 |
|
|
NeilG
Aged Yak Warrior
530 Posts |
Posted - 2008-05-04 : 09:37:11
|
| There is no need for the married in the when areaSELECT Name,Married =CASE MarriedWHEN 1 THEN 'Y' WHEN 0 THEN 'N'ELSE NULLEND,LastNamefrom Person |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-04 : 09:52:32
|
quote: Originally posted by hrishy HiI have a column of datatype bit.When i run a case statement i get a error.SELECT Name,Married =CASE Married WHEN Married = '1'THEN 'Y' WHEN Married = '0' THEN 'N' ELSE NULL END,LastNamefrom Person The above code gives a error message Msg 102, Level 15, State 1, Line 3Incorrect syntax near '='.regardsHrishy
If Married is of bit data type why are using single quotes for comparison? |
 |
|
|
hrishy
Starting Member
47 Posts |
Posted - 2008-05-06 : 05:39:41
|
| Hi EveryoneThanks for taking time out and replying to my post.I am not familiar with bit datatype and sqlserver in general.regardsHrishy |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-05-06 : 05:53:17
|
This has nothing with BIT datatype to do.It was the syntax with CASE WHEN. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
Sarvjita
Starting Member
1 Post |
Posted - 2011-06-17 : 04:31:01
|
| Try ThisSELECT Name,CASE Married WHEN Married = '1'THEN 'Y' WHEN Married = '0' THEN 'N' ELSE NULL END AS Married,LastNamefrom Person |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2011-06-19 : 02:40:42
|
No! This will give the same error as above. N 56°04'39.26"E 12°55'05.63" |
 |
|
|
|
|
|
|
|