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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Case Statement on a bit datatype

Author  Topic 

hrishy
Starting Member

47 Posts

Posted - 2008-05-04 : 07:41:13
Hi

I 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,
LastName
from Person


The above code gives a error message
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near '='.

regards
Hrishy

ayamas
Aged Yak Warrior

552 Posts

Posted - 2008-05-04 : 09:26:57
Try this

SELECT Name,Married =
CASE Married
WHEN 1 THEN 'Y'
WHEN 0 THEN 'N'
ELSE NULL
END,
LastName
from Person
Go to Top of Page

NeilG
Aged Yak Warrior

530 Posts

Posted - 2008-05-04 : 09:37:11
There is no need for the married in the when area

SELECT Name,
Married =
CASE Married
WHEN 1 THEN 'Y'
WHEN 0 THEN 'N'
ELSE NULL
END,
LastName
from Person
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-04 : 09:52:32
quote:
Originally posted by hrishy

Hi

I 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,
LastName
from Person


The above code gives a error message
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near '='.

regards
Hrishy


If Married is of bit data type why are using single quotes for comparison?
Go to Top of Page

hrishy
Starting Member

47 Posts

Posted - 2008-05-06 : 05:39:41
Hi Everyone

Thanks for taking time out and replying to my post.
I am not familiar with bit datatype and sqlserver in general.

regards
Hrishy
Go to Top of Page

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"
Go to Top of Page

Sarvjita
Starting Member

1 Post

Posted - 2011-06-17 : 04:31:01
Try This

SELECT Name,
CASE Married
WHEN Married = '1'THEN 'Y'
WHEN Married = '0' THEN 'N'
ELSE NULL
END AS Married,
LastName
from Person
Go to Top of Page

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"
Go to Top of Page
   

- Advertisement -