在我的存儲過程返回空值,我串聯我的結果到像一個字符串:的毗連結果在一個字符串中的存儲過程
Problem1|Problem2|Problem3
當我試圖在一個變量@display
來存儲,它將返回null 。當我運行查詢而不將其存儲到變量時,它會返回結果。不知道爲什麼它返回null?
declare @display nvarchar(500)
select
@display = @display + gp2.ProblemDesc + '|'
from (SELECT gp.GrantProblemID, gp.ProblemDesc, gps.GrantProblemStatus, row_number() over (partition by gp.grantproblemid order by p.periodid desc) ranking from MergedProgressReport.dbo.[PeriodAgencyGrantProblems] pagp
inner join MergedProgressReport.dbo.PeriodAgencyGrants pag on pag.PeriodAgencyGrantsID = pagp.PeriodAgencyGrantID and pag.GrantNumber = '2011UMWX0001'
inner join MergedProgressReport.dbo.periodagencyinfo pai on pag.PeriodAgencyInfoID = pai.PeriodAgencyInfoID inner join MergedProgressReport.dbo.Periods p on p.PeriodID = pai.PeriodID
inner join MergedProgressReport.dbo.GrantProblemStatus gps on pagp.GrantProblemStatusID = gps.GrantProblemStatusID inner join MergedProgressReport.dbo.GrantProblems gp on pagp.GrantProblemID = gp.GrantProblemID and gp.GrantProblemAreaID = 7) xx
right join MergedProgressReport.dbo.GrantProblems gp2 on xx.GrantProblemID = gp2.GrantProblemID and xx.ranking = 1 where gp2.GrantProblemAreaID = 7
Select @display
難道是因爲你有兩個結果集? – thebjorn 2013-03-03 12:20:16