SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Create sp from split
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

shanmugaraj
Posting Yak Master

219 Posts

Posted - 04/12/2013 :  02:06:04  Show Profile  Send shanmugaraj a Yahoo! Message  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
2217 Posts

Posted - 04/12/2013 :  02:10:39  Show Profile  Reply with Quote
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

Edited by - bandi on 04/12/2013 02:12:10
Go to Top of Page

shanmugaraj
Posting Yak Master

219 Posts

Posted - 04/12/2013 :  02:40:00  Show Profile  Send shanmugaraj a Yahoo! Message  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
2217 Posts

Posted - 04/12/2013 :  02:47:28  Show Profile  Reply with Quote
Is this format('Data$72,40$123428171,52456817') fixed? Will it give always 3 rows?

Edited by - bandi on 04/12/2013 02:47:58
Go to Top of Page

shanmugaraj
Posting Yak Master

219 Posts

Posted - 04/12/2013 :  03:10:53  Show Profile  Send shanmugaraj a Yahoo! Message  Reply with Quote
not fixed it is dynamic can grow

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

bandi
Flowing Fount of Yak Knowledge

India
2217 Posts

Posted - 04/12/2013 :  03:19:46  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000