SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


procedure


procedure

Author
Message
dastagirid
dastagirid
Old Hand
Old Hand (344 reputation)Old Hand (344 reputation)Old Hand (344 reputation)Old Hand (344 reputation)Old Hand (344 reputation)Old Hand (344 reputation)Old Hand (344 reputation)Old Hand (344 reputation)

Group: General Forum Members
Points: 344 Visits: 248
hi,

i used .net c# .here i created one array. that array have two values ..


how can i create array parameter in sql procedure



regards:
Dastagiri.D

Thanks
Dastagiri.D
alim.shaikh
alim.shaikh
SSC Journeyman
SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)

Group: General Forum Members
Points: 90 Visits: 36
unfortunately, sql server doesn't provide array since it is not a full fledge programming language. although the problem can be solved using concatenated string with some specific delimiter. for e.g. if you want to pass two values like ID1 and ID2 then you can use comma(,) to separate these two IDs. that means your string wud be like ID1,ID2 then in stored procedure you can parse these string by finding comma(,).
if you need sample then please let me know.
dastagirid
dastagirid
Old Hand
Old Hand (344 reputation)Old Hand (344 reputation)Old Hand (344 reputation)Old Hand (344 reputation)Old Hand (344 reputation)Old Hand (344 reputation)Old Hand (344 reputation)Old Hand (344 reputation)

Group: General Forum Members
Points: 344 Visits: 248
thanks..


give me one souce example



regards:
Dastagiri.D

Thanks
Dastagiri.D
alim.shaikh
alim.shaikh
SSC Journeyman
SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)

Group: General Forum Members
Points: 90 Visits: 36
Thanks for your interest,
Following is the example. hope it will help you for your problem.


Create Function [dbo].[fn_ParseDelimitedStrings]

(@String nvarchar(3500), @Delimiter char(1))

Returns @Values Table

(

RowId int Not Null Identity(1,1) Primary Key

,Value nvarchar(255) Not Null

)

As

Begin

Declare @startPos smallint

,@endPos smallint

If (Right(@String, 1) != @Delimiter)

Set @String = @String + @Delimiter

Set @startPos = 1

Set @endPos = CharIndex(@Delimiter, @String)

While @endPos > 0

Begin

Insert @Values(Value)

Select LTrim(RTrim(SubString(@String, @startPos, @endPos - @startPos)))

-- remove the delimiter just used

Set @String = Stuff(@String, @endPos, 1, '')

-- move string pointer to next delimiter

Set @startPos = @endPos

Set @endPos = CharIndex(@Delimiter, @String)

End

Return

End


Thanks
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)

Group: General Forum Members
Points: 222904 Visits: 42003
You can use a While loop if you want... but I wouldn't... Wink See the following...
http://www.sqlservercentral.com/articles/T-SQL/63003/

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
RBarryYoung
RBarryYoung
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: General Forum Members
Points: 36346 Visits: 9518
dastagirid (1/30/2009)
i used .net c# .here i created one array. that array have two values ..

There are lots of ways to do it, but for two values, they aren't worth it. Just pass two parameters.

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)

Group: General Forum Members
Points: 222904 Visits: 42003
RBarryYoung (1/31/2009)
dastagirid (1/30/2009)
i used .net c# .here i created one array. that array have two values ..

There are lots of ways to do it, but for two values, they aren't worth it. Just pass two parameters.


Heh... in the land of computers, I forgot to use the pencil. Tongue

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
RBarryYoung
RBarryYoung
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: General Forum Members
Points: 36346 Visits: 9518
alim.shaikh (1/31/2009)
unfortunately, sql server doesn't provide array since it is not a full fledge programming language...


This is incorrect on two counts. first, SQL is a "full-fledged" programming language. Really. Perhaps you meant to say that SQL is not a "general Purpose" programming language, which is true. SQL is a full-fledged special-purpose programming language.

Secondly, SQL does have a data structure that is more than the functional equivalent of arrays. They are called "Tables" and they are the preferred way of storing and manipulating array-like data in SQL. You should only use other means to emulate arrays when a table will not work (usually for interfacing reasons).

And actually, now there is a second data structure that is the functional equivalent of arrays and then some: XML. And there are at least six (6) other data types that can emulate them with varying degrees of difficulty. But I would say that tables are still preferred.

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)SSC Guru (222K reputation)

Group: General Forum Members
Points: 222904 Visits: 42003
RBarryYoung (1/31/2009)
alim.shaikh (1/31/2009)
unfortunately, sql server doesn't provide array since it is not a full fledge programming language...


This is incorrect on two counts. first, SQL is a "full-fledged" programming language. Really. Perhaps you meant to say that SQL is not a "general Purpose" programming language, which is true. SQL is a full-fledged special-purpose programming language.

Secondly, SQL does have a data structure that is more than the functional equivalent of arrays. They are called "Tables" and they are the preferred way of storing and manipulating array-like data in SQL. You should only use other means to emulate arrays when a table will not work (usually for interfacing reasons).

And actually, now there is a second data structure that is the functional equivalent of arrays and then some: XML. And there are at least six (6) other data types that can emulate them with varying degrees of difficulty. But I would say that tables are still preferred.


"The Force is strong in this one."

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
RBarryYoung
RBarryYoung
SSC-Dedicated
SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)SSC-Dedicated (36K reputation)

Group: General Forum Members
Points: 36346 Visits: 9518
Heh. "The ability to destroy a planet is insignificant next to the power of the force."

-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search