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 |
|
IBoonZ
Yak Posting Veteran
53 Posts |
Posted - 2009-03-20 : 05:47:10
|
| Hi I have following collumnsSuite_ID/ Product_ID / Suiteproduct / Name Suite /1 // 10 // 1_10 // suite12 // 15 // 2_15 // Suite23 // 20 // 3_20 // Suite 3-1 // 25 // -1_25 // NULLI want in the Name_Suite Collumn that when Suite_ID = -1the Name_suite Collumn says 'NO_SUITE'.I tried Case when Suite_Id = '-1' THEN Name_suite = 'No Suite Available' else NULL end as Name_suite. But he gives errors :(.Thanks :) |
|
|
karthik_padbanaban
Constraint Violating Yak Guru
263 Posts |
Posted - 2009-03-20 : 05:53:04
|
| Try with this.select Case Suite_Id when -1 THEN 'NO_SUITE' else Name_suite end as Name_suite from table_name If it still gives error. post the error.Karthik |
 |
|
|
IBoonZ
Yak Posting Veteran
53 Posts |
Posted - 2009-03-20 : 06:01:54
|
| he :).No error here. Thx for the help |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-03-20 : 06:19:48
|
| In this statement Case when Suite_Id = '-1' THEN Name_suite = 'No Suite Available' else NULL end as Name_suite. What's the error u got , just Post that error Once. |
 |
|
|
IBoonZ
Yak Posting Veteran
53 Posts |
Posted - 2009-03-20 : 06:31:11
|
| Incorrect syntax near '='. |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-03-20 : 06:54:57
|
This is also work for uCase when Suite_Id = '-1' THEN Name_suite = 'No Suite Available' else NULL end as Name_suite. |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-03-20 : 08:47:52
|
| Case when Suite_Id = '-1' THEN 'No Suite Available' else NULL end as Name_suiteor Name_suite = Case when Suite_Id = '-1' THEN 'No Suite Available' else NULL end |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-20 : 09:42:02
|
| this will also do job for youSELECT COALESCE(NULLIF(Name_suite,-1),'NO_SUITE') FROM table_name |
 |
|
|
|
|
|