 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Bruce McIver Guest
|
Posted: Mon Jul 04, 2005 8:43 am Post subject: TableName as parameter |
|
|
Hi,
I'm trying to execute a very simple query within SQL Server. I want to pass
a parameter - representing a table - from Delphi to SQL. I then want to
populate that table.
e.g
CREATE PROCEDURE CreateNewTable (@TableName char(15))
AS
SELECT *
INTO @TableName
FROM OldTable
GO
I realise I probably can't use a datatype of char(15) to represent the table
that I want to populate, but what is the simplest way to do this? I can
create a Query within delphi and execute this code successfully but I want
to do it at the SQL end.
Thanks
Bruce.
|
|
| Back to top |
|
 |
Yannis Guest
|
Posted: Mon Jul 04, 2005 9:19 am Post subject: Re: TableName as parameter |
|
|
Bruce McIver wrote:
| Quote: | Hi,
I'm trying to execute a very simple query within SQL Server. I want
to pass a parameter - representing a table - from Delphi to SQL. I
then want to populate that table.
e.g
CREATE PROCEDURE CreateNewTable (@TableName char(15))
AS
SELECT *
INTO @TableName
FROM OldTable
GO
I realise I probably can't use a datatype of char(15) to represent
the table that I want to populate, but what is the simplest way to do
this? I can create a Query within delphi and execute this code
successfully but I want to do it at the SQL end.
Thanks
Bruce.
|
You can't do it this way you need to create the sql command as text and
use the sp_sqlEXEC stored procedure to execute any string that contains
an sql statement.
CREATE PROCEDURE CreateNewTable (@TableName char(15))
AS
Declare sSQL varchar(8000)
SET SQL = 'SELECT * INTO ' + @TableName + ' FROM OldTable '
sp_SQLExec(sSQL);
GO
|
|
| Back to top |
|
 |
Bruce McIver Guest
|
Posted: Mon Jul 04, 2005 10:11 am Post subject: Re: TableName as parameter |
|
|
Thanks for that Yannis.
Unfortunately I am using SQL Server 2000 and I have just read the following
regarding sp_sqlexec:
"Removed; no longer available. Remove all references to sp_sqlexec."
"Yannis" <None (AT) noware (DOT) non> wrote
| Quote: | Bruce McIver wrote:
Hi,
I'm trying to execute a very simple query within SQL Server. I want
to pass a parameter - representing a table - from Delphi to SQL. I
then want to populate that table.
e.g
CREATE PROCEDURE CreateNewTable (@TableName char(15))
AS
SELECT *
INTO @TableName
FROM OldTable
GO
I realise I probably can't use a datatype of char(15) to represent
the table that I want to populate, but what is the simplest way to do
this? I can create a Query within delphi and execute this code
successfully but I want to do it at the SQL end.
Thanks
Bruce.
You can't do it this way you need to create the sql command as text and
use the sp_sqlEXEC stored procedure to execute any string that contains
an sql statement.
CREATE PROCEDURE CreateNewTable (@TableName char(15))
AS
Declare sSQL varchar(8000)
SET SQL = 'SELECT * INTO ' + @TableName + ' FROM OldTable '
sp_SQLExec(sSQL);
GO
|
|
|
| Back to top |
|
 |
Thomas Steinmaurer Guest
|
Posted: Mon Jul 04, 2005 10:39 am Post subject: Re: TableName as parameter |
|
|
| Quote: | Thanks for that Yannis.
Unfortunately I am using SQL Server 2000 and I have just read the following
regarding sp_sqlexec:
"Removed; no longer available. Remove all references to sp_sqlexec."
|
Try sp_executesql.
--
HTH,
Thomas Steinmaurer
LogManager Series - Logging/Auditing Suites supporting
InterBase, Firebird, Advantage Database, MS SQL Server and
NexusDB V2 (NEW!)
Upscene Productions
http://www.upscene.com
|
|
| Back to top |
|
 |
Bruce McIver Guest
|
Posted: Mon Jul 04, 2005 1:07 pm Post subject: Re: TableName as parameter |
|
|
Yep, had noticed that sp_executesql was the SQL 2000 equivalent.
Thanks.
"Thomas Steinmaurer" <t.steinmaurer (AT) _no_upscene_spam_ (DOT) com> wrote
| Quote: | Thanks for that Yannis.
Unfortunately I am using SQL Server 2000 and I have just read the
following
regarding sp_sqlexec:
"Removed; no longer available. Remove all references to sp_sqlexec."
Try sp_executesql.
--
HTH,
Thomas Steinmaurer
LogManager Series - Logging/Auditing Suites supporting
InterBase, Firebird, Advantage Database, MS SQL Server and
NexusDB V2 (NEW!)
Upscene Productions
http://www.upscene.com
|
|
|
| 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
|
|