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

SQL Server durch Komma getrennt

declare @T table (Address_col varchar(20))

insert into @T values
('Nevada,USA'),
('Tokyo,Japan'),
('Hanoi,Vietnam')

select left(Address_col, charindex(',', Address_col)-1) as Address_col,
       stuff(Address_col, 1, charindex(',', Address_col), '') as Country
from @T

Aktualisierung:
Die Aufteilung eines Strings in drei Teile kann so aussehen:declare @T table (Address_col varchar(20))

insert into @T values
('Nevada,USA,World'),
('Tokyo,Japan,World'),
('Hanoi,Vietnam,World')

select parsename(C, 3),
       parsename(C, 2),
       parsename(C, 1) 
from @T
  cross apply (select replace(Address_col, ',', '.')) as T(C)