 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Ryan Schoolman Guest
|
Posted: Fri Dec 12, 2003 1:11 am Post subject: sql server 2000 stored procedures |
|
|
How do you create a temp table of the result that is returned from a stored
procedure
example would be nice
--
Ryan Schoolman - Programmer & Application Architect
[email]ryan (AT) pclegends (DOT) com[/email]
PC Legends
http://www.pclegends.com
[w] 715.839.6855
[c] 715.379.0878
[h] 715.855.9003
|
|
| Back to top |
|
 |
Ross Guest
|
Posted: Fri Dec 12, 2003 1:46 pm Post subject: Re: sql server 2000 stored procedures |
|
|
Ryan Schoolman wrote:
| Quote: | How do you create a temp table of the result that is returned from a stored
procedure
example would be nice
If you have control over the stored proc do something like this: |
create proc TableListing
as
begin
create table #MyTables (TableName sysname, TableID int)
insert #MyTables (TableName, TableID) select Name, ID from sysobjects
where xtype = 'u '
select * from #MyTables
end
if you don't have control over stored proc you could do this:
create table #TempTable1 (
same structure as returned from StoredProc in question)
insert into #TempTable1 exec StoredProcInQuestion
This is all untested so it might require some tweaking but should work
either way.
HTH
Ross
|
|
| Back to top |
|
 |
Ryan Schoolman Guest
|
Posted: Fri Dec 12, 2003 2:01 pm Post subject: Re: sql server 2000 stored procedures |
|
|
What if I don't know the table structure of the stored procedure results
because they are dynamic.
I wouldn't like to modify the stored procedure if possible.
"Ross" <polks71 (AT) hotmail (DOT) com> wrote
| Quote: | Ryan Schoolman wrote:
How do you create a temp table of the result that is returned from a
stored
procedure
example would be nice
If you have control over the stored proc do something like this:
create proc TableListing
as
begin
create table #MyTables (TableName sysname, TableID int)
insert #MyTables (TableName, TableID) select Name, ID from sysobjects
where xtype = 'u '
select * from #MyTables
end
if you don't have control over stored proc you could do this:
create table #TempTable1 (
same structure as returned from StoredProc in question)
insert into #TempTable1 exec StoredProcInQuestion
This is all untested so it might require some tweaking but should work
either way.
HTH
Ross
|
|
|
| Back to top |
|
 |
Gbenga Abimbola Guest
|
Posted: Fri Dec 12, 2003 4:42 pm Post subject: Re: sql server 2000 stored procedures |
|
|
You should know the structure of the table that you will be creating with a stored procedure. Otherwise, how do you want to manipulate the table?
"Ryan Schoolman" <ryan (AT) infinitejoy (DOT) com> wrote:
| Quote: | What if I don't know the table structure of the stored procedure results
because they are dynamic.
I wouldn't like to modify the stored procedure if possible.
"Ross" <polks71 (AT) hotmail (DOT) com> wrote in message
news:3fd9c6b9$1 (AT) newsgroups (DOT) borland.com...
Ryan Schoolman wrote:
How do you create a temp table of the result that is returned from a
stored
procedure
example would be nice
If you have control over the stored proc do something like this:
create proc TableListing
as
begin
create table #MyTables (TableName sysname, TableID int)
insert #MyTables (TableName, TableID) select Name, ID from sysobjects
where xtype = 'u '
select * from #MyTables
end
if you don't have control over stored proc you could do this:
create table #TempTable1 (
same structure as returned from StoredProc in question)
insert into #TempTable1 exec StoredProcInQuestion
This is all untested so it might require some tweaking but should work
either way.
HTH
Ross
|
|
|
| Back to top |
|
 |
Ross Guest
|
Posted: Fri Dec 12, 2003 7:21 pm Post subject: Re: sql server 2000 stored procedures |
|
|
I am not aware of a way to make a temp table without knowing the
structure of it before hand. I guess there could be a way of enumerating
the fields but not sure if that is possible in sql.
You might want to try the MS SQL SErver groups someone there might know
how to do that.
Ross
|
|
| Back to top |
|
 |
Oscar Santiesteban Jr. Guest
|
Posted: Sun Dec 14, 2003 7:42 pm Post subject: Re: sql server 2000 stored procedures |
|
|
Why don't you do something like:
select * into #TEMPTABLE
from your_table
inside of your stored procedure?
Oscar...
"Ryan Schoolman" <ryan (AT) infinitejoy (DOT) com> wrote
| Quote: | What if I don't know the table structure of the stored procedure results
because they are dynamic.
I wouldn't like to modify the stored procedure if possible.
"Ross" <polks71 (AT) hotmail (DOT) com> wrote in message
news:3fd9c6b9$1 (AT) newsgroups (DOT) borland.com...
Ryan Schoolman wrote:
How do you create a temp table of the result that is returned from a
stored
procedure
example would be nice
If you have control over the stored proc do something like this:
create proc TableListing
as
begin
create table #MyTables (TableName sysname, TableID int)
insert #MyTables (TableName, TableID) select Name, ID from sysobjects
where xtype = 'u '
select * from #MyTables
end
if you don't have control over stored proc you could do this:
create table #TempTable1 (
same structure as returned from StoredProc in question)
insert into #TempTable1 exec StoredProcInQuestion
This is all untested so it might require some tweaking but should work
either way.
HTH
Ross
|
|
|
| Back to top |
|
 |
John Shearing Guest
|
Posted: Mon Dec 15, 2003 5:18 am Post subject: Re: sql server 2000 stored procedures |
|
|
Hi Ryan,
| Quote: | What if I don't know the table structure of the stored procedure results
because they are dynamic.
I wouldn't like to modify the stored procedure if possible.
|
This is easy to accomplish.
All you need to do is create a stored procedure that creates string which is
ment to be executed.
The following is a very simple example of granting permissions to a stored
procedure who's name is not known until this code is run.
--Grant permission on the sproc we are building for our secure user.
SET @SQLString1 = 'GRANT EXECUTE ON sp' + @TableObject + 'Add TO SecureUser'
EXEC (@SQLString1)
There is no reason that you can't use this same technique to create temp
tables or any other kind of object.
I use this technique in my application generator to create a set of stored
procedures for each table to handle:
Adds, Updates, and Deletes,
Creating application wide unique Ids for each record,
Maintaining an Audit trail for each table,
Posting to the general ledger,
Rolling down changes to dependent tables,
Cascading deletes,
Transactions and rollbacks,
Calling validation and business rule stored procedures,
Calling postprocessing stored procedures
Translating words
Importing and revalidating data,
Security, and more.
There is one bugaboo with temp tables created this way, and that is that the
temp table will be created and destroyed within the execution of the string.
So any actions to be taken on those tables must be included in the command
string.
I hope this all makes sense.
Best, John
|
|
| Back to top |
|
 |
Ross Guest
|
Posted: Tue Dec 16, 2003 9:04 pm Post subject: Re: sql server 2000 stored procedures |
|
|
John Shearing wrote:
| Quote: | Hi Ryan,
What if I don't know the table structure of the stored procedure results
because they are dynamic.
I wouldn't like to modify the stored procedure if possible.
This is easy to accomplish.
All you need to do is create a stored procedure that creates string which is
ment to be executed.
The following is a very simple example of granting permissions to a stored
procedure who's name is not known until this code is run.
--Grant permission on the sproc we are building for our secure user.
SET @SQLString1 = 'GRANT EXECUTE ON sp' + @TableObject + 'Add TO SecureUser'
EXEC (@SQLString1)
There is no reason that you can't use this same technique to create temp
tables or any other kind of object.
The problem with this approach that I have not been able to figure out |
is how do know the field names at run time, in SQL. It is easy yes to
insert a table name and pull fields into Delphi and have Delphi parse
the fields for you. But to parse the field names, types, and sizes in
SQL at run time I have not seen a solution to this. I would gladly use
it but I have not found one nor have I figured it out.
Ross
|
|
| Back to top |
|
 |
Tony J Hopkinson Guest
|
Posted: Tue Dec 16, 2003 9:40 pm Post subject: Re: sql server 2000 stored procedures |
|
|
On Tue, 16 Dec 2003 15:04:07 -0600, Ross <polks71 (AT) hotmail (DOT) com> wrote:
| Quote: | John Shearing wrote:
Hi Ryan,
What if I don't know the table structure of the stored procedure results
because they are dynamic.
I wouldn't like to modify the stored procedure if possible.
This is easy to accomplish.
All you need to do is create a stored procedure that creates string which is
ment to be executed.
The following is a very simple example of granting permissions to a stored
procedure who's name is not known until this code is run.
--Grant permission on the sproc we are building for our secure user.
SET @SQLString1 = 'GRANT EXECUTE ON sp' + @TableObject + 'Add TO SecureUser'
EXEC (@SQLString1)
There is no reason that you can't use this same technique to create temp
tables or any other kind of object.
The problem with this approach that I have not been able to figure out
is how do know the field names at run time, in SQL. It is easy yes to
insert a table name and pull fields into Delphi and have Delphi parse
the fields for you. But to parse the field names, types, and sizes in
SQL at run time I have not seen a solution to this. I would gladly use
it but I have not found one nor have I figured it out.
Ross
You can get this data from the syscolumns table, there are a number of |
"metatable " tables in SQL Server. Systables will give you alist of
all the tables and their ids. the table id you can then use as a key
in syscolumns to get out the columns in said tables type infor etc.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|