Thursday, March 16, 2017

sql return no records found if there is no data in table

I am facing an issue in which if i don't have any record in table so i need to show No record is found.

DECLARE  @customerid  AS numeric=14922  
select 'test' as 'Column',(case when  IsEnabled=1 then 'Yes' else 'No' end)as 'Status' from customer where Customer_id=@customerid
UNION ALL
SELECT  'test' as 'Column','No' AS Status
WHERE NOT EXISTS (SELECT 1
   FROM customer S
   WHERE s.Customer_id = @customerid)
 
   UNION ALL
   select 'test' as 'Column',(case when  IsEnabled=1 then 'Yes' else 'No' end)as 'Status' from customer where Customer_id=@customerid
UNION ALL
SELECT  'test' as 'Column','No' AS Status
WHERE NOT EXISTS (SELECT 1
   FROM customer S
   WHERE s.Customer_id = @customerid)
   

No comments:

Post a Comment