I want to split this string "name#email#mobile#country" using #, and insert those 4 values into a table.
The table columns are: id, name, email, mobile, country
I have to make it using SQL, not from any programming language.
I want to split this string "name#email#mobile#country" using #, and insert those 4 values into a table.
The table columns are: id, name, email, mobile, country
I have to make it using SQL, not from any programming language.
Let's check the link below. I think it will help you well
This SQL will split a string to columns based on #
declare @str varchar(100)
set @str = 'name123#email123#mobile123#country123'
SELECT @str,
substring(@str, 1, charindex('#',@str) - 1)'name',
substring(@str, charindex('#',@str) + 1, charindex('#',@str, charindex('#',@str) + 1) - charindex('#',@str) - 1) 'email',
substring(@str, charindex('#',@str, charindex('#',@str) + 1) + 1, charindex('#',@str, charindex('#',@str, charindex('#',@str) + 1) + 1) - charindex('#',@str, charindex('#',@str) + 1) - 1)'mobile',
substring(@str, charindex('#',@str, charindex('#',@str, charindex('#',@str) + 1) + 1) + 1, len(@str)) 'country'