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
 General SQL Server Forums
 New to SQL Server Programming
 Msg 245, Level 16, State 1, Line 1

Author  Topic 

CP
Starting Member

9 Posts

Posted - 2012-03-29 : 14:08:38
I am using Microsoft SQL Server Management Studio 2008. With the query below I am getting this error:
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value 'Red' to data type int.

SELECT 
CAST(CASE COLORS
WHEN 0 THEN 'Pink'
WHEN 1 THEN 'Yellow'
WHEN 2 THEN 'Red'
WHEN 3 THEN 'Blue'
ELSE TABLE_TEST
END AS varchar(20)) AS Color_Labels


I just need a way to change the numbers to colors. Thank you for your help!

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-29 : 14:11:27
What is TABLE_TEST?

I'm guessing that it's a column in your table that's defined as an int



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-29 : 14:12:49
[code]
SELECT
CASE COLORS
WHEN 0 THEN 'Pink'
WHEN 1 THEN 'Yellow'
WHEN 2 THEN 'Red'
WHEN 3 THEN 'Blue'
ELSE CAST(TABLE_TEST AS varchar(20))
END AS Color_Labels
[/code]

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

CP
Starting Member

9 Posts

Posted - 2012-03-29 : 14:14:34
That worked thank you!
Go to Top of Page
   

- Advertisement -