Home All Groups Group Topic Archive Search About

passing a table from one sp to another sp

Author
15 Sep 2006 12:49 AM
SQL Ken
WHAT ARE THE OPTIONS do i have to pass a table from  from one sp to
another?

write the data into a table and then use it from the other won't do the
job for me.


thanks

ken

Author
15 Sep 2006 1:03 AM
Chris Lim
SQL Ken wrote:
> WHAT ARE THE OPTIONS do i have to pass a table from  from one sp to
> another?
>
> write the data into a table and then use it from the other won't do the
> job for me.

Without writing the table into either a #temp table or work table, you
have no options.
Author
15 Sep 2006 1:12 AM
Arnie Rowland
You asked for options:

1. Combine the sprocs so you don't have to pass anything
2. Rewrite your queries so that trying to pass a table is unnecessary.
3. Create a Table Valued Function (TVF) that is used by both sprocs.
4. Declare 23,999 variables and pass them as parameters (choose your own
number...)
5. Write the data out to a file and then read the file back in
or.
6. Create and use a #Temp table

With SQL Server 2005, you could create a xml datatype variable, and then
pass that as a ntext parameter, converting back to xml.

See Ward's article, the 'sidebar' at the bottom:

http://www.microsoft.com/technet/technetmag/issues/2005/05/SQLXML/default.aspx


--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous


Show quote
"SQL Ken" <SQL***@gmail.com> wrote in message
news:1158281375.217094.273850@i42g2000cwa.googlegroups.com...
> WHAT ARE THE OPTIONS do i have to pass a table from  from one sp to
> another?
>
> write the data into a table and then use it from the other won't do the
> job for me.
>
>
> thanks
>
> ken
>
Author
15 Sep 2006 2:38 AM
Mike C#
"Arnie Rowland" <ar***@1568.com> wrote in message
news:%23KaoBQG2GHA.1256@TK2MSFTNGP02.phx.gbl...
> With SQL Server 2005, you could create a xml datatype variable, and then
> pass that as a ntext parameter, converting back to xml.

ntext is deprecated and "will be removed in a future version of SQL Server"
according to BOL.  Maybe nvarchar(max)?
Author
15 Sep 2006 4:13 AM
Arnie Rowland
I think you're right about using varchar(max) instead.

--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous


Show quote
"Mike C#" <x**@xyz.com> wrote in message
news:qmoOg.347$%W2.231@newsfe10.lga...
>
> "Arnie Rowland" <ar***@1568.com> wrote in message
> news:%23KaoBQG2GHA.1256@TK2MSFTNGP02.phx.gbl...
>> With SQL Server 2005, you could create a xml datatype variable, and then
>> pass that as a ntext parameter, converting back to xml.
>
> ntext is deprecated and "will be removed in a future version of SQL
> Server" according to BOL.  Maybe nvarchar(max)?
>
Author
15 Sep 2006 4:23 AM
Mike C#
"Arnie Rowland" <ar***@1568.com> wrote in message
news:OSXab1H2GHA.3588@TK2MSFTNGP06.phx.gbl...
>I think you're right about using varchar(max) instead.

You can also declare parameters to your SP's as xml data type without
casting to a character type
Author
15 Sep 2006 7:07 AM
SQL Ken
Arnie,
Thought of all your suggested but didn't work.
Can't use a Temp table because it get detroyed after the sp is
executed.
can't pass a table into a function.
can't write data into a table and read it in from another becuase,
multiple users can execute the sp's at once.
Can't combine the sp's becuae they are in two diffent servers and I
conect to the remotely.
can't use open query, becaue i can't pass in the parameters.

I am not familiar with XML datatype but will look into that as an
option. However, my srver is 2000.

Your input is highly appreciated
Ken.
Author
15 Sep 2006 7:15 AM
Arnie Rowland
> can't write data into a table and read it in from another because,
> multiple users can execute the sp's at once.

You could add a column or two and include the spid, or system_user(), both
of which are unique to the user, and known to any sproc.

--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
Author
15 Sep 2006 7:55 AM
Chris Lim
SQL Ken wrote:
> Can't use a Temp table because it get detroyed after the sp is
> executed.

If you create the temp table in the calling procedure, then it will be
available to the called procedure(s) and still exist afterwards (until
you drop it or the calling procedure exits).

e.g.

Proc1:

CREATE TABLE #temp1(...)

INSERT #temp1....

EXEC Proc2

SELECT * FROM #temp1


Proc2:

UPDATE #temp1.....
etc

Chris
Author
15 Sep 2006 8:13 AM
SQL Ken
Thanks,
I will try this

Ken
Chris Lim wrote:
Show quote
> SQL Ken wrote:
> > Can't use a Temp table because it get detroyed after the sp is
> > executed.
>
> If you create the temp table in the calling procedure, then it will be
> available to the called procedure(s) and still exist afterwards (until
> you drop it or the calling procedure exits).
>
> e.g.
>
> Proc1:
>
> CREATE TABLE #temp1(...)
>
> INSERT #temp1....
>
> EXEC Proc2
>
> SELECT * FROM #temp1
>
>
> Proc2:
>
> UPDATE #temp1.....
> etc
>
> Chris
Author
15 Sep 2006 1:27 PM
Anith Sen
For some options, see:
http://www.sommarskog.se/share_data.html

--
Anith

AddThis Social Bookmark Button