MSSQL STRING_AGG() Conversion failed when converting the varchar value to int.

  • does it work if you try

    DECLARE @ids NVARCHAR(max)
    select @ids = string_agg(inserted.[lo_location], ',')
    from (select X.query('.').value('(row/lo_Location)[1]', 'int') as lo_location
    --, X.query('.').value('(row/lo_Location_Code)[1]', 'nvarchar(100)') as lo_location_Code
    from @inserted.nodes('inserted/row') as T (X)
    ) as inserted
  • Thanks Frederico. Your code is good but it appears the error was later in my code. Apologies for not posting the whole code set but it was long and convoluted. Thanks for your input.

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

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