Sunday, July 23, 2017

Testing a comparison operator in an SQL Query?

Let us say we want to know if a variable x is greater or less than another variable y. How do we write a query to test it?

One way to do this is as follows:

declare @x int
set @x=5
declare @y int
set @y=10
    IF @x < @y
 print 1
    ELSE
 print 0

No comments:

Post a Comment

Install the latest version of SQL Server Management Studio 20.2

This is the latest version of SQL Server Management Studio [build no:20.2.30.0, released July 9,2024]. Note: it is not an upgrade to SQL Ser...