Click here to Skip to main content
14,331,194 members
Rate this:
Please Sign up or sign in to vote.
See more:
i pass the parameter to stored procedure as string "RET:WHO:IMP:XMP"
now i wane to split this string as different string RET WHO IMP XMP. how can I?
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 8

Hi,

Try This

CREATE FUNCTION [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


And

SELECT * from Split('RET:WHO:IMP:XMP',':')


Hope this will help you.

Cheers
   
Rate this:
Please Sign up or sign in to vote.

Solution 7

Try this link, hope this will be helpful for you.

http://sharmanuj.blogspot.in/2014/07/how-to-split-string-in-sql-server.html[^]
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

Another link here
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

This link-SQL Server Split Function[^] might help you.
   
Comments
Monjurul Habib 4-Jul-11 15:03pm
   
nice link, my 5.
Rate this:
Please Sign up or sign in to vote.

Solution 2

Here more than couple of ways

Split String in SQL[^]
   
Comments
Monjurul Habib 4-Jul-11 15:02pm
   
nice link, my 5.
Rate this:
Please Sign up or sign in to vote.

Solution 1

   
Comments
Monjurul Habib 4-Jul-11 15:02pm
   
nice link, my 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100