I have a column with data like
I~A~G~S
How could i separate them using select query.
Output : Updated
Rows Column(Data)
First I
Second A
Third G
Fourth S
I have a column with data like
I~A~G~S
How could i separate them using select query.
Output : Updated
Rows Column(Data)
First I
Second A
Third G
Fourth S
declare @s varchar(10)
set @s='I~A~G~S'
select replace(@s,'~',' ')
for updated question
create table #vij11 (s varchar(100))
insert into #vij11(s) values ('I~A~G~S')
SELECT
Split.a.value('.', 'VARCHAR(100)') AS String
FROM (SELECT [s],
CAST ('<M>' + REPLACE([s], '~', '</M><M>') + '</M>' AS XML) AS String
FROM #vij11) AS A CROSS APPLY String.nodes ('/M') AS Split(a);
if you are using oracle database then it should be as follows:
select replace('I~A~G~S','~',' ') as x from dual;
select replace(<fieldname>,'~',' ') from <tablename>
as for the question of splitting the string in different rows please check the below query.
SELECT trim(regexp_substr(replace('I~A~G~S','~',','), '[^,]+', 1, LEVEL)) str_2_tab
FROM dual
CONNECT BY LEVEL <= regexp_count(replace('I~A~G~S','~',','), ',')+1;