FLash
FLash

Reputation: 746

SQL Server - Cast result of logical expression as BIT/INT

Why the query below is not working? Doesn't a logical expression return a boolean/bitwise value?

SELECT @v1 = CAST( (@v2 > 0) AS INT)

Upvotes: 5

Views: 1389

Answers (1)

PSK
PSK

Reputation: 17943

Following statement will do what you are trying to achieve.

SELECT @V1 = IIF ( @V2 > 0, 1, 0 ) 

Upvotes: 6

Related Questions