I want to insert values into employee table.
And those values are in string format ~ separated
E.g: AA~B~123
I am splitting it using following function
CREATE FUNCTION [db_owner].[FN_Split] (@String varchar(8000), @Delimiter char(1))
returns @temptable TABLE (items varchar(8000))
as
begin
declare @idx int
declare @slice varchar(8000)
select @idx = 1
if len(@String)<1 or @String is null return
while @idx!= 0
begin
set @idx = charindex(@Delimiter,@String)
if @idx!=0
set @slice = left(@String,@idx - 1)
else
set @slice = @String
if(len(@slice)>0)
insert into @temptable(Items) values(@slice)
set @String = right(@String,len(@String) - @idx)
if len(@String) = 0 break
end
return
end
Now I get Output as
SELECT * FROM db_owner.FN_Split('AA~B~123','~')
Output
items
______
AA
B
123
Now I am stuck here
How can I insert above values in employee table???
like
insert into employee (name,add,phone)
values('AA','B','123');
Please guide.
Tried this but not working
insert into employee
SELECT * FROM db_owner.FN_Split('AA~BB~CC','~')
ERROR
Msg 213, Level 16, State 1, Line 1
Column name or number of supplied values does not match table definition.
if you could add a small counter into the stored procedure like this then life would be easier:
Your subsequent query could be something like the following:
But have you tried changing the procedure so that it outputs the data in a horizontal format rather than the vertical output that you currently have?