views:

110

answers:

2

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?

+2  A: 

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.

Adam Robinson
@gbn: Maybe I wasn't clear: I'm saying that you cannot assign a *boolean expression* to a `bit` column. That is, this isn't legal: `update MyTable set BitColumn = @param1 < @param2`.
Adam Robinson
@Adam Robinson: sorry, I misunderstood, downvote removed
gbn
A: 

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
gbn