tags:

views:

42

answers:

3

This is what I thought would be a simple select clause, however the following is giving me grief! I am using SQL Server 2008.

Basically I want to compare two integer values and return the boolean result in the select clause. Here is a simple example:

DECLARE @A INT
DECLARE @B INT
SET @A = 1
SET @B = 2

SELECT @A = @B

Currently the only output is "Command(s) completed successfully." Where I reasonably believe it is assigning @A to @B.

I thought this would be simple but have not been able to achieve this.

Any help would be great! Thanks

+3  A: 
Select Case When @A = @B Then 1 Else 0 End
Thomas
+1  A: 

try

SELECT CASE WHEN @A = @B THEN 1 ELSE 0 END

instead

Manu
A: 

Where I reasonably believe it is assigning @A to @B.

No... it is assigning B to A.

You need this:

SELECT case when @A - @B = 0 then 1 else 0 end
slugster