Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

SQL Server diviso per virgola

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

Aggiornamento:
Dividi una stringa in tre parti può essere simile a questa: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)