Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,
i want to show bellow comma separate string to Table columns header names how can i do can any one suggest me.

"UOM,TF1,TF2,TF3"


----TABLE 
UOM  TF1  TF2   TF3
Posted
Updated 27-Feb-15 21:45pm
v2
Comments
OriginalGriff 28-Feb-15 3:46am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
What are you tryingt o do that you want this? There may be a simpler way.
Use the "Improve question" widget to edit your question and provide better information.
Zoltán Zörgő 28-Feb-15 4:08am    
Is the number of values in the string fixed?
John C Rayan 28-Feb-15 4:33am    
Th question is unclear.

1 solution

Hi,

Whatever i understand from your input....you can try below


SQL
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

SQL
SELECT * from Split('UOM,TF1,TF2,TF3',',')


Hope this will help you.

Cheers
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900