SELECT 15 > 14 FROM Duel;
Working in MySql but not in SqlServer
SQL Error(102): Incorrect syntax near '>'
I have a requirement where I want to see if at least 1 record exist return 1 or else 0
SELECT count(emp.name) > 0
FROM ****
WHERE *** IN (***)
Check the db fiddle https://dbfiddle.uk/?rdbms=sqlserver_2017&fiddle=348709a562ad02cbe88abf01a37229f1
November 14, 2019 at 4:34 am
IF (SELECT count(emp.name) FROM **** WHERE *** IN (***)) > 0
BEGIN
SELECT 1;
END;
ELSE
BEGIN
SELECT 0;
END;
I ended up using IIF
SELECT IIF(count(erm.employee_code) > 0, 1, 0)
FROM ****
WHERE *** IN (***)
November 18, 2019 at 10:55 am
If you just want to know if there are any such records it is usually better to use "exists" rather than making SQL Server provide a full count
IF exists (SELECT null FROM **** WHERE *** IN (***))
BEGIN
SELECT 1;
END;
ELSE
BEGIN
SELECT 0;
END;
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy