SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Msg 245, Level 16, State 1, Line 1
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

CP
Starting Member

9 Posts

Posted - 03/29/2012 :  14:08:38  Show Profile  Reply with Quote
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 - 03/29/2012 :  14:11:27  Show Profile  Reply with Quote
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 - 03/29/2012 :  14:12:49  Show Profile  Reply with Quote

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


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 - 03/29/2012 :  14:14:34  Show Profile  Reply with Quote
That worked thank you!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000