October 7, 2013 at 3:32 pm
I am looking for help on splitting a string and select nth occurrence only to display like
@String='123,0.934,98,928.34,987.45'
The above string contains 5 values delimited by Comma.
I need to display only 3rd split - 98
I need to display only 5th split value - 987.45
I could find functions to display all values together, but I want only nth occurrence only.
I appreciate your kind help.
October 7, 2013 at 3:38 pm
You could use the delimited split function by Jeff Moden:
Tally OH! An Improved SQL 8K “CSV Splitter” Function[/url]
It returns a table with the various parts and their positions, so you select only those you need.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
October 7, 2013 at 3:53 pm
Thanks for the reply.
I reviewed your suggestion, would you please let me know how can I use the function run time in a SQL insert statement.
October 7, 2013 at 5:07 pm
Use it as any other TVF
DECLARE @String varchar(100)='123,0.934,98,928.34,987.45'
SELECT *
FROM dbo.DelimitedSplit8K(@String, ',')
WHERE ItemNumber IN(3,5)
October 8, 2013 at 1:31 am
Ramesh Mutyapu (10/7/2013)
Thanks for the reply.I reviewed your suggestion, would you please let me know how can I use the function run time in a SQL insert statement.
Come now, you have to do at least a little bit of the effort yourself 😉
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply