不确定为什么Crystal不喜欢这个SP查询:我在Crystal的子报表中调用它并将@RTGID
作为参数从主报表传递到子报表:
ALTER procedure [dbo].[USP_RTG_RoutingSAE_HeaderOPs]
(@RTGId nvarchar(40))
as
Create Table #RoutingReport(Letters varchar(max),IDs varchar(max))
;WITH Unpivoted AS
( SELECT upvt.Uf_RTG_Operation, Letters
FROM (select * from UDT_RoutingSAE where UDT_RoutingSAE.Uf_RTG_RoutingId = @RTGId) a
UNPIVOT
( Value
FOR Letters IN ([Uf_RTG_A],[Uf_RTG_B],[Uf_RTG_C],[Uf_RTG_D],[Uf_RTG_E],[Uf_RTG_F],[Uf_RTG_G],[Uf_RTG_H],[Uf_RTG_I],[Uf_RTG_J],[Uf_RTG_K],[Uf_RTG_L],[Uf_RTG_M]
,[Uf_RTG_N],[Uf_RTG_O],[Uf_RTG_P],[Uf_RTG_Q],[Uf_RTG_R],[Uf_RTG_S],[Uf_RTG_T],[Uf_RTG_U],[Uf_RTG_V],[Uf_RTG_W],[Uf_RTG_X],[Uf_RTG_Y],[Uf_RTG_Z],[Uf_RTG_AA],[Uf_RTG_AB]
,[Uf_RTG_AC],[Uf_RTG_AD],[Uf_RTG_AE],[Uf_RTG_AF],[Uf_RTG_AG],[Uf_RTG_AH],[Uf_RTG_AI],[Uf_RTG_AJ],[Uf_RTG_AK],[Uf_RTG_AL],[Uf_RTG_AM],[Uf_RTG_AN],[Uf_RTG_AO],[Uf_RTG_AP]
,[Uf_RTG_AQ],[Uf_RTG_AR],[Uf_RTG_AS],[Uf_RTG_AT],[Uf_RTG_AU],[Uf_RTG_AV],[Uf_RTG_AW],[Uf_RTG_AX],[Uf_RTG_AY],[Uf_RTG_AZ])
) upvt
WHERE upvt.Value = 1
)
Insert into #RoutingReport
SELECT Letters = REPLACE(u.Letters, 'Uf_RTG_', ''),
IDs = STUFF(( SELECT ', ' + CAST(u2.Uf_RTG_Operation AS VARCHAR(max))
FROM Unpivoted u2
WHERE u.Letters = u2.Letters
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)'), 1, 2, '')
FROM Unpivoted u
GROUP BY u.Letters;
(select c.Letters,c.IDs,d.Uf_RTG_Name,d.Uf_RTG_RoutingId,e.UF_RTG_Description
from #RoutingReport c
inner join UDT_SameAsExceptDefinitions d
on d.Uf_RTG_Code = c.Letters
inner join UDT_RoutingHeader e
on e.Uf_RTG_RoutingId = d.Uf_RTG_RoutingId
where d.Uf_RTG_RoutingId= @RTGId and e.Uf_RTG_RoutingId=@RTGId)
drop table #RoutingReport
Return
答案 0 :(得分:0)
知道了。只需要在SP中添加Begin和End。问题解决了!