Tuesday, June 26, 2018

How to execute the query only when record count is not zero

You can achieve this in many ways, the easiest way is, use SELECT TOP 1 1 FROM TABLE

SELECT TOP 1 = Selecting the very 1st record in the result set


SELECT 1 = return 1 as the result set


SELECT TOP 1 1 FROM [SomeTable] WHERE <SomeCondition> Means if the condition is true and any rows are returned from the select, only return top 1 row and only return integer 1 for the row (no data just the integer 1 is returned).


Cheers!
Uma