Link to home
Start Free TrialLog in
Avatar of HNA071252
HNA071252Flag for United States of America

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
ASKER CERTIFIED SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
btw - those are not double-quotes (") but two single-quotes together ('')
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HNA071252

ASKER

Thanks. It works actually with one single quote, not two.