sql - No Column Name on executing stored procedure -
i working on stored proc suppose give values based on input quarter , year.
the stored proc has dynamic 2 columns has sum of amounts. in place of column name showing no column name 2 columns (s1, p1) , not giving values.
create proc [dbo].[summary] @quarter int, @year int begin declare @sc decimal(18,0) declare @po decimal(18,0) declare @inv decimal(18,0) select bd.id, bd.project, status, (select sum(amount) s1 details status = 's1' , bd.project = a.project), (select sum(amount) p1 details b status = 'p1' , bd.project = b.project) projectdetails (nolock) bd inner join details (nolock) d on bd.project = d.project bd.quarter = @quarter , bd.year = @year , bd.project = d.project group bd.lineid, bd.project, status end
when use function in column list, original column name not retained. need use column alias. example:
select bd.id, bd.project, status, (select sum(amount) s1 details status = 's1' , bd.project = a.project) sums1, --added alias here (select sum(amount) p1 details b status = 'p1' , bd.project = b.project) sump1 --and here ... as why not getting data, because query not returning data. try running select statements separately see problem is.
Comments
Post a Comment