February 3, 2014 at 5:29 am
hello all
I Have this function:
CREATE FUNCTION dbo.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
I run this function:
select * from dbo.Split('1234567890,2,''92/11/14'',''92/11/17'',''92/11/14'',9214,''92/11/14'',''92/11/14'',1,4,''منطقه 2''' ,',')
now I need to use from function result for sp parameter:
Exec mysp a,b,c,d,e,f,g,h,i,j,k
I need to this:a=1234567890
b=2
c='92/11/14' and ....
how do i do this?
thanks
February 3, 2014 at 5:36 am
Pass the string into the stored procedure as a string parameter and split it there. Splitting it first and attempting to pass in all of the resolved elements as a parameter each is unlikely to look nice or more importantly play nice.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
February 3, 2014 at 5:44 am
please write T-Sql for me.thanks
February 3, 2014 at 5:51 am
elham_azizi_62 (2/3/2014)
please write T-Sql for me.thanks
If I do this, you will remain a novice. You must at least make an attempt to write the TSQL.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
February 3, 2014 at 5:57 am
I am in hurry and I don't have time and I have to give it to my boss immediately.please help me.
February 3, 2014 at 7:26 am
elham_azizi_62 (2/3/2014)
I am in hurry and I don't have time and I have to give it to my boss immediately.please help me.
We are not here to be unpaid consultants. We are here to help people with issues and learn t-sql. We are willing and able to help but most people around here are not going to just give you the code.
For what it worth, the splitter function that you posted is horrible inefficient. If you want to find a much better one for performance, take a look at the article in my signature about splitting strings.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
February 3, 2014 at 7:41 am
elham_azizi_62 (2/3/2014)
I am in hurry and I don't have time and I have to give it to my boss immediately.please help me.
Something so timecritical should not be subject to the whims and timezones of folks on a forum.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
February 3, 2014 at 12:02 pm
elham_azizi_62 (2/3/2014)
I run this function:select * from dbo.Split('1234567890,2,''92/11/14'',''92/11/17'',''92/11/14'',9214,''92/11/14'',''92/11/14'',1,4,''????? 2''' ,',')
now I need to use from function result for sp parameter:
Exec mysp a,b,c,d,e,f,g,h,i,j,k
I need to this:a=1234567890
b=2
c='92/11/14' and ....
how do i do this?
thanks
Pretty much like you did near the bottom. You'll need to do a SELECT INTO from that function into a Temp Table and then write code to equate each row in the temp table (accroding to the IDX column) to a variable.
There's no fast way to do this. This is going to take you a little time.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply