.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Sql Server >> Post New QuestionBookmark and Share Subscribe to Forum

String split in sql2005

Posted By: PRATHAP     Posted Date: January 08, 2013    Points:5   Category :Sql Server
im trying to split the string in sql2005 depends on the comma character.but that string is not split entirely.
here is the code and result

DECLARE @SPLITSTRING VARCHAR(max)
DECLARE @CAT VARCHAR(max)
DECLARE @SUBCAT VARCHAR(max)
DECLARE @POS INT
DECLARE @STARTPOS INT
DECLARE @CITY VARCHAR(8000)
DECLARE @PRICE FLOAT

SET @STARTPOS=0

SET @SPLITSTRING='prathap,Radharamanan'

SET @POS=CHARINDEX(',',@SPLITSTRING)
SET @CAT=SUBSTRING(@SPLITSTRING,@STARTPOS,@POS)

SET @STARTPOS=@POS+1

SET @POS=CHARINDEX(',',@SPLITSTRING)
SET @SUBCAT=SUBSTRING(@SPLITSTRING,@STARTPOS,@POS)

print @cat
print @subcat

OUTPUT
prathap
Radharam

try to help me to resolve this issue


Responses
Author: Petr Matejovsky             
Posted Date: January 18, 2013     Points: 20   

Hi,

try this:

...
...

SET @STARTPOS=0

SET @SPLITSTRING='prathap,Radharamanan'

SET @POS=CHARINDEX(',',@SPLITSTRING)
SET @CAT=SUBSTRING(@SPLITSTRING,@STARTPOS,@POS)

SET @STARTPOS=@POS+1

SET @SUBCAT=SUBSTRING(@SPLITSTRING,@STARTPOS,LEN(@SPLITSTRING) - @POS)

print @cat
print @subcat




SUBSTRING ( expression ,start , length )


Petr Matejovsky, Pemasoft


Author: Deco             
Posted Date: August 01, 2013     Points: 20   

World smallest T-SQL to split a string is available in the below URL

http://www.dotnetbites.com/split-strings-into-table

Regards,
Deco


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend