Question

Not sure why Crystal does not like this SP query: I am calling this in the subreport from Crystal and passing the @RTGID as parameter from the main report to the subreport:

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
Was it helpful?

Solution

Got it. Just needed to add a Begin and an End to the SP. Problem solved!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top