Is there to easily build a comma delimited list from parameters that are passed. I know you can do it with COALESCE and a table but not with parameters:
I am trying to get the string to show:
'Zero rows when: @Name = Main, @Number = 2, @ClassName= AnotherClass'
Thanks,
Tom
Code:
DECLARE @Name varchar(100),
@Number int,
@ClassName varchar(100),
@ErrorMessage varchar(2000
SELECT @Name = 'Main',
@Number = 2,
@ClassName = 'AnotherClass'
SELECT @ErrorMessage = 'Zero rows when: ' +
CASE WHEN @Name IS NULL THEN '' ELSE COALESCE(@ErrorMessage + ', ', '') + '@Name = ' + @Name END +
CASE WHEN @Number IS NULL THEN '' ELSE COALESCE(@ErrorMessage + ', ', '') + '@Number = ' + CONVERT(varchar(10),@Number) END +
CASE WHEN @ClassName IS NULL THEN '' ELSE COALESCE(@ErrorMessage + ', ', '') + '@ClassName = ' + @ClassName END
SELECT @ErrorMessage
I am trying to get the string to show:
'Zero rows when: @Name = Main, @Number = 2, @ClassName= AnotherClass'
Thanks,
Tom