0

I'm thinking this is easy, but I'm having a hard time manifesting. I have a list of values, e.g.

@bob
@sarah
@kelly;john
@denver_colorado
@james12;kellybelly

I want the list to be:

@bob
@sarah
@kelly
@john
@denver_colorado
@james12
@kellybelly

essentially, splitting a line after ";" and add @ as a prefix to all values

Ronaldo
  • 6,017
  • 2
  • 13
  • 43
teddy
  • 11
  • 1

1 Answers1

1

Use the SPLIT_STRING function to separate the string on each ';' Use the REPLACE function to change all '@' to a ';' so this also signals a split. Prefix the value with '@'

declare @s nvarchar(max)

set @s = '@bob @sarah @kelly;john @denver_colorado @james12;kellybelly'

SELECT '@' + value FROM SPLIT_STRING(REPLACE(@string, '@', ';'), ';')