I am separating a varchar
according to spaces
(I know the no. of spaces)
I am using a stored procedure (Recursive)
to do so
Alter procedure [dbo].[1234]
@name varchar(100),
@count int
AS
BEGIN
if @count=1
begin
set @name=SUBSTRING(@name,CHARINDEX(' ',@name,1)+1,LEN(@name))
select @name
end
if @count>1
begin
select SUBSTRING(@name,1,CHARINDEX(' ',@name,1)-1)
set @count=@count-1
set @name=SUBSTRING(@name,CHARINDEX(' ',@name,1)+1,LEN(@name))
exec [dbo].[1234] @name,@count
end
END
I execute the following SP on
exec [dbo].[1234] 'a b c d e f g h',8
And my result is
but i want my result as
Here's a SQL Fiddle demo.