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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SQL working with arrays

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-06-13 : 08:02:29
Maximiliano writes "Hi, I need to know how does SQL works with arrays and matrix, how do you define them in the language. I know its a stupid question but if you could help me with that I would really appreciate it.
Thanks!
Best Regards.
Maximiliano Mazzera"

macka
Posting Yak Master

162 Posts

Posted - 2002-06-13 : 08:32:50
SQL doesn't support arrays, but its possible to pass delimited strings to stored procedures and then process the string into individual elements. Take a look at this article:


[url]http://www.sqlteam.com/item.asp?ItemID=637[/url]

macka.

Go to Top of Page

inancgumus
Starting Member

40 Posts

Posted - 2002-06-13 : 08:49:06
'how does SQL works with arrays'
--> it does not.
but there is a few techniques for implementing
array like processes. one of them is the stack
technique.

in the stack technique you push and pull items
from your data.

say we have a list of formatted items like this:
'123,456,23,123'

say again these are the id numbers which
are indicating records of the another table.
we can pop the items with a stored procedure
and within an another process, we can process
the items.

say our popper procedure's name is:
spPopFirstItem.

we can call this procedure for retrieving
items from our data.

-- we are creating our data
DECLARE @sOurData nvarchar(64)
SET @sOurData = '123,456,23,123'

-- we are popping the first item
-- with calling our s.procedure
DECLARE @sPoppedItem nvarchar(10)
spPopFirstItem(
@sPoppedItem OUTPUT
,@sOurData OUTPUT
)

/*
the result of this process is:

@sOurData will '456,23,123'
@sPoppedItem will '123'

look that, the first item of the
@sOurData is cutted off and
@sPoppedItem variable's value is
the first item of our old @sOurData
variable.
*/

You can find more information about
the stacks and how to implement
stacks in the sql server by
searching&browsing the related web
sites.

Inanc GUMUS


Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-06-13 : 09:02:52
quote:

Hi, I need to know how does SQL works with arrays and matrix, how do you define them in the language. I know its a stupid question but if you could help me with that I would really appreciate it.



RDBMS are set-based systems. Arrays, queues, stacks, etc are iterative concepts. Work with your data in tables and use joins to perform DML on sets of data rather than iterating through individual members of an array/queue/stack.... This is fundamental to the relational model.

Tell us a bit more about what you are trying to accomplish and we can show you a set based solution that will give much better performance than iterative processing.

<O>
Go to Top of Page

indywizard
Starting Member

1 Post

Posted - 2002-06-13 : 09:42:01
There is a better approach to passing arrays ->

Use a text parameter to pass in an XML document in a string, then use the XML commands and presto.....

Read up on the following commands that you will need to do this
sp_xml_preparedocument
OPENXML
sp_xml_removedocument
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-06-13 : 09:45:35
quote:
Use a text parameter to pass in an XML document in a string, then use the XML commands and presto.....

Ahhhhhh, got an easy way to pass data INTO a text parameter? I'd love to see it. Oh, by the way, WITHOUT using ADO.

Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-06-13 : 09:54:25
quote:

There is a better approach to passing arrays ->...


Who ever said anything about passing arrays? The question was how does SQL Server work with them and how you define them? Why is every post on this thread (excluding mine of course) talking about passing data to a stored proc? That isn't the question, is it?

<O>
Go to Top of Page
   

- Advertisement -