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 END   

output:

  id text date id-5  

expected 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

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -