Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Create sp from split

Author  Topic 

shanmugaraj
Posting Yak Master

219 Posts

Posted - 2013-04-12 : 02:06:04
Hi i have data as
Data$72,40$123428171,524568179

I need to write an sp passing these parameter..
kindly help
select * from split('Data$72,40$123428171,524568179','$')

create sp syntax needed

THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-12 : 02:10:39
Do you need SP for splitting Delimiter Separated Values ? or this?

CREATE PROCEDURE @TestProc
@P_DSVParam VARCHAR(1000) -- Input Param for passing Delimiter separated values
AS
BEGIN
-- Your Logic
select * from split(@P_DSVParam ,'$')
END
Go to Top of Page

shanmugaraj
Posting Yak Master

219 Posts

Posted - 2013-04-12 : 02:40:00
I need sp to pass the values from the resultset of [select* from split ]

ie :
select * from split('Data$72,40$123428171,524568179','$') will return
item
Data
72,40
123428171,524568179

i want to pass in sp the 2nd and 3rd row data each in param

THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-12 : 02:47:28
Is this format('Data$72,40$123428171,52456817') fixed? Will it give always 3 rows?
Go to Top of Page

shanmugaraj
Posting Yak Master

219 Posts

Posted - 2013-04-12 : 03:10:53
not fixed it is dynamic can grow

THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-12 : 03:19:46
If that format is fixed 'Value1$Value2$Value3', then you don't need any other user-defined functions

DECLARE @P_DSVParam VARCHAR(1000) = 'Data$72,40$123428171,524568179' -- Input Param for passing Delimiter separated values
DECLARE @V_Value2 VARCHAR(100), @V_Value3 VARCHAR(100), @startPos INT, @EndPos INT
SELECT @startPos= CHARINDEX('$', @P_DSVParam), @EndPos = CHARINDEX('$', REVERSE(@P_DSVParam))
SELECT @V_Value2 = SUBSTRING( @P_DSVParam, @startPos+1, LEN(@P_DSVParam)-(@endPos+@startPos) ),
@V_Value3 = RIGHT( @P_DSVParam, @EndPos-1)
SELECT @V_Value2, @V_Value3


Tell us the purpose of SP... we can try in another way...
Go to Top of Page
   

- Advertisement -