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 |
|
stumbling
Posting Yak Master
104 Posts |
Posted - 2007-04-16 : 07:21:06
|
Hi AllI have a column in a table of type float it contains supplied qty's.I would like to run the following statement thru a case statment when the value is < 0SELECT '-' + right(replace(replicate('0', 10) + (cast(qtysupplied as varchar)), '-', ''),10) FROM table_nameHaving not used case statements before in any detail i have gotten this far but as someone out there can obviously see i am lost. Any help would be appreciatedselect CASE When qtysupplied > = 0 Then qtysupplied ELSE (SELECT '-' + right(replace(replicate('0', 10) + (cast(qtysupplied as varchar)), '-', ''),10) FROM table_name) ENDfrom table_name  |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-04-16 : 07:29:47
|
quote: Originally posted by stumbling Hi AllI have a column in a table of type float it contains supplied qty's.I would like to run the following statement thru a case statment when the value is < 0SELECT '-' + right(replace(replicate('0', 10) + (cast(qtysupplied as varchar)), '-', ''),10) FROM table_nameHaving not used case statements before in any detail i have gotten this far but as someone out there can obviously see i am lost. Any help would be appreciatedselect CASE When qtysupplied > = 0 Then qtysupplied ELSE (SELECT '-' + right(replace(replicate('0', 10) + (cast(qtysupplied as varchar)), '-', ''),10) FROM table_name) ENDfrom table_name 
select CASE When qtysupplied > = 0 Then cast(qtysupplied as varchar) ELSE '-' + right(replace(replicate('0', 10) + (cast(qtysupplied as varchar)), '-', ''),10)END as qtysuppliedfrom table_name Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
stumbling
Posting Yak Master
104 Posts |
Posted - 2007-04-16 : 07:43:35
|
Thank you very much for this, i can now see where i was going wrong. Very much appreciated.Cheers. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-04-16 : 09:43:09
|
| If you want to show this formatted data at front end, you can use format function thereMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|