SQL Server - Compare int values ​​in select clause

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

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

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

SELECT @A = @B

At the moment, the only result is "Team completed successfully." Where I reasonably believe that he assigns @A to @B.

I thought it would be easy, but I could not achieve this.

Any help would be great! Thanks

+3
source share
3 answers

try

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

instead

+4
source
Select Case When @A = @B Then 1 Else 0 End
+4
source

, @A @B.

... B A.

:

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

Source: https://habr.com/ru/post/1738576/


All Articles