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 |
Gekko
Yak Posting Veteran
63 Posts |
Posted - 2011-07-18 : 05:01:47
|
hallo.....allhow convert num on bit (column status)my sql statement not work:CAST(CASE WHEN TabProduct.quantity <=0 THEN 0 ELSE 1 END AS BIT)for example:TabProductsName........quantity.......statusmonitor........3.............1mouse..........8.............1notebook.......2.............1apple..........0.............0i-phone........0.............0thanks all |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-07-18 : 05:08:19
|
do you have negative quantity value ? if not, you can just useselect Name, quantity, convert(bit, quantity) as statusfrom TabProducts KH[spoiler]Time is always against us[/spoiler] |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2011-07-18 : 05:13:51
|
Why not use SIGN?SELECT Name, Quantity, SIGN(Quantity) AS [Status] FROM dbo.tabProducts N 56°04'39.26"E 12°55'05.63" |
 |
|
Gekko
Yak Posting Veteran
63 Posts |
Posted - 2011-07-18 : 05:15:44
|
thanks khtan and SwePeso that's it |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-07-18 : 05:29:05
|
sign will return 1, -1 or 0. Not exactly a bit data type KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|