Sqlserver
 sql >> Datenbank >  >> RDS >> Sqlserver

Irritative Hilfe bei SQL-Anweisungen erforderlich

Sie können Ihre E-Mail-Liste in XML konvertieren und dann das XML mit .nodes abfragen und .value .

declare @T table
(
  ID int,
  Emails varchar(100)
)

insert into @T values
(1, '[email protected], [email protected]'),
(2, '[email protected], [email protected]')

select T.Email, count(*) as [Count]
from (
      select X.N.value('.',  'varchar(30)') as Email
      from @T
        cross apply (select cast('<x>'+replace(Emails, ', ', '</x><x>')+'</x>' as xml)) as T(X)
        cross apply T.X.nodes('/x') as X(N)
     ) as T
group by T.Email

Ergebnis:

Email                          Count
------------------------------ -----------
[email protected]               1
[email protected]              2
[email protected]              1