I have this stored procedure, and I want to add a column name to the value I'm getting. Where should I add the
as "TotalNewspapers"
(or whatever I have to add) if Im using the COALESCE?
SELECT COALESCE ((SELECT
count(distinct Appendage.AppendageName) as "TotalNewspapers"
FROM Edition
inner join SourceInformation on (SourceInformation.SourceInformationID = Edition.SourceInformationID)
left join Appendage on (Appendage.AppendageID = Edition.AppendageID)
inner join Pages on (Edition.EditionID = Pages.EditionID)
where
Edition.publishdate >= DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)
and Edition.publishdate <= DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0)+1
and Pages.PullBy is null
and Edition.FinishDate is null
group by Appendage.AppendageName, SourceInformation.SourceInformationName, Pages.PullBy, Edition.FinishDate, Appendage.AppendageID
having count(Pages.PullBy) > 1) , 0);
1条答案
按热度按时间pxy2qtax1#
You can use ISNULL or COALESCE :
I remove sub-query, all you need can be done in one select statement. Also add aliases .