Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Show one record if table is empty

Author  Topic 

thiyait
Yak Posting Veteran

70 Posts

Posted - 2014-04-25 : 10:05:43
Hi everyone,

I have a query

select salesId,count(*) from salesline group by salesid
Result will be
salesid Nos
----- ---
SO001 2
SO002 4

i want to display single record like below if there is no record avaible in the table

salesid Nos
So00? 0

Please help

Thanks and regards,
Thiya.t

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2014-04-25 : 10:20:31
you'd have to do something like this:

if exists(select 1 from salesline)
begin
select salesId,count(*) as Nos from salesline group by salesid
end
else
begin
select 'So00?' as salesID, 0 as Nos
end


Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -