Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

procedure Expand / Collapse
Author
Message
Posted Friday, January 30, 2009 8:56 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, December 2, 2009 12:19 AM
Points: 108, 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
Post #647445
Posted Saturday, January 31, 2009 12:48 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, May 12, 2009 4:56 AM
Points: 12, 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.
Post #647464
Posted Saturday, January 31, 2009 12:53 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, December 2, 2009 12:19 AM
Points: 108, Visits: 248
thanks..


give me one souce example



regards:
Dastagiri.D


Thanks
Dastagiri.D
Post #647465
Posted Saturday, January 31, 2009 1:16 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, May 12, 2009 4:56 AM
Points: 12, 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
Post #647468
Posted Saturday, January 31, 2009 7:11 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 7:08 PM
Points: 35,593, Visits: 32,187
You can use a While loop if you want... but I wouldn't... ;) 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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #647610
Posted Saturday, January 31, 2009 8:55 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 11:54 AM
Points: 9,294, Visits: 9,492
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."
Post #647633
Posted Saturday, January 31, 2009 9:00 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 7:08 PM
Points: 35,593, Visits: 32,187
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. :P


--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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #647635
Posted Saturday, January 31, 2009 9:05 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 11:54 AM
Points: 9,294, Visits: 9,492
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."
Post #647640
Posted Saturday, January 31, 2009 9:10 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 7:08 PM
Points: 35,593, Visits: 32,187
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #647641
Posted Saturday, January 31, 2009 9:27 PM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Yesterday @ 11:54 AM
Points: 9,294, Visits: 9,492
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."
Post #647650
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse