HNA071252
asked on
sql server 2005 - case when syntax
Could you please help me correct the case when syntax in this?
DECLARE @strSQL NVARCHAR(MAX)
DECLARE @COLS NVARCHAR(2000)
SELECT @COLS = STUFF((SELECT distinct
'], [' + convert(varchar, [Date], 112)
FROM TRP.FFS_PHID order by 1
FOR XML PATH('')
), 1, 2, '') + ']'
set @strSQL = N'SELECT Tab, PhID, SG_Regm, ProdLine
, case when Product = 'Salud' then 'Salud' case when Product = 'SLV' then 'Silver' case when Product = 'BRZ' then 'Bronze' else 'FUL' end, ' + @Cols
+ N' FROM TRP.FFS_PHID
PIVOT (SUM (FullProj) FOR [Date] IN (' + @Cols + N')) AS pt'
EXEC sp_executesql @strSQL
DECLARE @strSQL NVARCHAR(MAX)
DECLARE @COLS NVARCHAR(2000)
SELECT @COLS = STUFF((SELECT distinct
'], [' + convert(varchar, [Date], 112)
FROM TRP.FFS_PHID order by 1
FOR XML PATH('')
), 1, 2, '') + ']'
set @strSQL = N'SELECT Tab, PhID, SG_Regm, ProdLine
, case when Product = 'Salud' then 'Salud' case when Product = 'SLV' then 'Silver' case when Product = 'BRZ' then 'Bronze' else 'FUL' end, ' + @Cols
+ N' FROM TRP.FFS_PHID
PIVOT (SUM (FullProj) FOR [Date] IN (' + @Cols + N')) AS pt'
EXEC sp_executesql @strSQL
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
btw - those are not double-quotes (") but two single-quotes together ('')
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. It works actually with one single quote, not two.