Re: nested stored procedures and returning lots of rows



(codefragment@xxxxxxxxxxxxxx) writes:
I have a chunky bit of sql that I will want to call from a number of
places. It will return a
few thousand rows. Whats the best way of structuring this?

1) I initially thought of using nested stored procedures and returning
the result in a temporary
table. However the scope of the temporary table seems to be limited to
the stored procedure
its created in so unless I create the temporary table in every stored
proc that needs to use
this generic one it won't work. If I create it in the generic stored
proc then the called stored procs can't see it

2) Insert the rows into a real table with a guid. Once the call has
finished delete those rows.
Scoping is now not an issue?

3) A view? I haven't had any experience with these but I don't believe
they can take arguments
which makes them useless for this

I discuss possible alternatives on an article on my web site,
http://www.sommarskog.se/share_data.html. I cover both your first and
second alternative there. Views are not doable, but a function could
make it for you.

--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.



Relevant Pages

  • Re: SQL 2005
    ... The SQL Server implementation is not just Stored Procs, ... it works very tightly in proc with the SQL Server Engine(most ... Now with all that I have said T-SQL is not going away and is still a needed ... >> the CLR is now supported in stored procedures and triggers. ...
    (borland.public.delphi.non-technical)
  • Re: Help with SQL 2005 and Sourcesafe 6
    ... That doesn't seem to be the case with stored procedures. ... compile that latest version to be table to use it. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (microsoft.public.sqlserver.tools)
  • Re: Error msg
    ... > I have corrected my stored procedures with what you said. ... In an interface like ADO you would iterate over ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (microsoft.public.data.oledb)
  • Re: Error msg
    ... > The stored procedures looks like this: ... > // update record table here ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (microsoft.public.data.oledb)
  • Re: Select query help+primary key
    ... While SELECT * is handy when running ad hoc-queries, ... Finding which stored procedures is simple, ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)