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 |
|
SpeshulK926
Starting Member
16 Posts |
Posted - 2007-05-08 : 14:02:08
|
| I have a stored procedure SELECT statement that will return 3 different numbers, "1, 2, and 3". I need to put in some static text instead of the numbers, so it will look like this...SELECT FieldName FROM TableNameIF FieldName = '1' THEN = 'Text1',IF FieldName = '2' THEN = 'Text2',IF FieldName = '3' THEN = 'Text3'I know that is now how you do it, but close as I could get to knowing what I want to do... Anyone can help? |
|
|
jezemine
Master Smack Fu Yak Hacker
2886 Posts |
Posted - 2007-05-08 : 14:07:15
|
You want to check out the CASE statment in sql.select case FieldName when 1 then 'text1' when 2 then 'text2' when 3 then 'text3' endfrom yourtable www.elsasoft.org |
 |
|
|
SpeshulK926
Starting Member
16 Posts |
Posted - 2007-05-08 : 14:16:52
|
quote: Originally posted by jezemine You want to check out the CASE statment in sql.select case FieldName when 1 then 'text1' when 2 then 'text2' when 3 then 'text3' endfrom yourtable www.elsasoft.org
Worked great! 1 more question, how do I name the table? I tried case FieldName when 1 then 'text1' as FieldNameIWant when 2 then 'text2' as FieldNameIWant when 3 then 'text3' as FieldNameIWant endalso tried case FieldName as FieldNameIWant when 1 then 'text1' when 2 then 'text2' when 3 then 'text3'Both threw an exception... |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-05-08 : 14:24:44
|
| case FieldNamewhen 1 then 'text1'when 2 then 'text2'when 3 then 'text3'end as FieldNameIWantPeter LarssonHelsingborg, Sweden |
 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-05-09 : 03:15:47
|
quote: Originally posted by SpeshulK926 I have a stored procedure SELECT statement that will return 3 different numbers, "1, 2, and 3". I need to put in some static text instead of the numbers, so it will look like this...SELECT FieldName FROM TableNameIF FieldName = '1' THEN = 'Text1',IF FieldName = '2' THEN = 'Text2',IF FieldName = '3' THEN = 'Text3'I know that is now how you do it, but close as I could get to knowing what I want to do... Anyone can help?
Just a thoughtIf you put static text with column values, you can useSelect 'static_text'+cast(col as varchar(10)) from tableThough this seems presentation issue MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|