for xml path and STUFF missing the first character

  • Hi

    I have SELECT --CheckDate,
    stuff((
      SELECT DISTINCT ',' + ProcessName
      FROM [database].[dbo].[DataLoadCheck] as t1
      where t1.CheckDate = t2.CheckDate and IsProcessed = 0
      FOR XML PATH('')
      ), 1, 2, '')
    FROM [database].[dbo].[DataLoadCheck] as t2
    GROUP BY CheckDate

    but my results are missing the first character of the first word

    help

  • hoseam - Tuesday, October 31, 2017 1:18 AM

    Hi

    I have SELECT --CheckDate,
    stuff((
      SELECT DISTINCT ',' + ProcessName
      FROM [database].[dbo].[DataLoadCheck] as t1
      where t1.CheckDate = t2.CheckDate and IsProcessed = 0
      FOR XML PATH('')
      ), 1, 2, '')
    FROM [database].[dbo].[DataLoadCheck] as t2
    GROUP BY CheckDate

    but my results are missing the first character of the first word

    help

    That's because you are replacing 2 characters instead of 1
    😎

    SELECT --CheckDate,
    stuff((
    SELECT DISTINCT ',' + ProcessName
    FROM [database].[dbo].[DataLoadCheck] as t1
    where t1.CheckDate = t2.CheckDate and IsProcessed = 0
    FOR XML PATH('')
    ), 1, 2, '')
    FROM [database].[dbo].[DataLoadCheck] as t2
    GROUP BY CheckDate

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply