amit
amit

Reputation: 11

TSQL Is returning boolean is not possible?

Can't i write something in TSQL

declare @set1 int
declare @set2 int
set @set1=1
set @set2=2

select @set1 < @set2

by getting true as result?

I Know i can use

case when @set<@set then 'true'

but can't i do by the way i have written above?

Upvotes: 1

Views: 916

Answers (2)

Adam Robinson
Adam Robinson

Reputation: 185703

No; T-SQL does not treat boolean expressions as data. In the same way, you couldn't assign a boolean expression directly to a bit field.

Upvotes: 2

gbn
gbn

Reputation: 432742

SQL Server has no "implied" type that would be boolean from an expression. In reality it could be any type to SQL server and it's arguably convention that says an expression is boolean in .net.

It has a bit data type that is almost like boolean and maps directly to boolean in client code and accepts true or false as strings.

DECLARE @foo bit
SET @foo = 'true' -- = 1

Upvotes: 0

Related Questions