Select statement to return constant when no records found in table in SQL Server 2008 -
I have a table with data and for example there is no record in the table, then returning the selection details in the zero Will happen . I need to use it in the processed process.
- If any records select in the selected statement below ID, text, date TBL data where ID = 12 if (@@ ROWCOUNT = 0) BEGIN SELECT-5 AS ID ENDoutput:
id text date id-5expected output < / B>
id-5
if If you want to return 1 row, even if there is no match, you can use aggregation:
(in case COUNT (*) = 0 THEN -5 ELSE MAX (ID) EN D) as ID from tblData WHERE ID = 12;
Comments
Post a Comment