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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 convert column on bit

Author  Topic 

Gekko
Yak Posting Veteran

63 Posts

Posted - 2011-07-18 : 05:01:47
hallo.....all

how 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:

TabProducts

Name........quantity.......status
monitor........3.............1
mouse..........8.............1
notebook.......2.............1
apple..........0.............0
i-phone........0.............0

thanks 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 use

select Name, quantity, convert(bit, quantity) as status
from TabProducts



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

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"
Go to Top of Page

Gekko
Yak Posting Veteran

63 Posts

Posted - 2011-07-18 : 05:15:44
thanks khtan and SwePeso
that's it
Go to Top of Page

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]

Go to Top of Page
   

- Advertisement -