 DECLARE @Columns VARCHAR(MAX) DECLARE @Convert VARCHAR(MAX)  SELECT  @Columns = STUFF((            SELECT '],[' + ErrClassfn              from ArchimedesTables.dbo.PM_ErrClassificationSetup             WHERE CONVERT(VARCHAR(00), ISNULL(EndDate, GETDATE()), 000)                            Between CONVERT(VARCHAR(00), GETDATE(), 000)                           AND     CONVERT(VARCHAR(00), GETDATE(), 000)             ORDER BY '],[' + CONVERT(VARCHAR(MAX), ID) ASC               FOR                   XML PATH('')            ), 0, 0, '') + ']'  SET @Convert = 'SELECT  