BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TableName as parameter

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Bruce McIver
Guest





PostPosted: Mon Jul 04, 2005 8:43 am    Post subject: TableName as parameter Reply with 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.


Back to top
Yannis
Guest





PostPosted: Mon Jul 04, 2005 9:19 am    Post subject: Re: TableName as parameter Reply with quote



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





PostPosted: Mon Jul 04, 2005 10:11 am    Post subject: Re: TableName as parameter Reply with 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."


"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





PostPosted: Mon Jul 04, 2005 10:39 am    Post subject: Re: TableName as parameter Reply with quote

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





PostPosted: Mon Jul 04, 2005 1:07 pm    Post subject: Re: TableName as parameter Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.