dbTalk Databases Forums  

Passing database name as a parameter to execute SQL task

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Passing database name as a parameter to execute SQL task in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Irene
 
Posts: n/a

Default Passing database name as a parameter to execute SQL task - 11-20-2006 , 07:21 PM






Hi there,
I am using DTS script for the conversion. I would like to get a
database name as a parameter from the user (through a command line),
assign it to the package global variable, and then use Execute SQL task
to drop and recreate a database with such name. However, I have
troubles passing a parameter to Execute SQL task.

The following syntax works:
DECLARE @ArchiveName VARCHAR
SET @ArchiveName = 'Conversion'
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name =
@ArchiveName)
BEGIN
EXEC ('DROP DATABASE' + @ArchiveName)
END

However, I need @ArchiveName to be a parameter set by user. Any attemts
to use parameters in Execute SQl task throw error:

DECLARE @ArchiveName VARCHAR
SET @ArchiveName = ?
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name =
@ArchiveName)
BEGIN
EXEC ('DROP DATABASE' + @ArchiveName)
END

And this:


IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name =
?)
BEGIN
EXEC ('DROP DATABASE' + ?)
END


Please let me know if you know how to make it work
Thanks a lot
Irene


Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Passing database name as a parameter to execute SQL task - 11-20-2006 , 11:07 PM






Hello Irene,


Have a look at this article to see how to accomplish this

http://www.sqldts.com/default.aspx?205


Regards

Allan Mitchell
Konesans Ltd
T +44 7966 476 572
F +44 2071 008 479
http://www.konesans.com

Quote:
Hi there,
I am using DTS script for the conversion. I would like to get a
database name as a parameter from the user (through a command line),
assign it to the package global variable, and then use Execute SQL
task
to drop and recreate a database with such name. However, I have
troubles passing a parameter to Execute SQL task.
The following syntax works:
DECLARE @ArchiveName VARCHAR
SET @ArchiveName = 'Conversion'
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name =
@ArchiveName)
BEGIN
EXEC ('DROP DATABASE' + @ArchiveName)
END
However, I need @ArchiveName to be a parameter set by user. Any
attemts to use parameters in Execute SQl task throw error:

DECLARE @ArchiveName VARCHAR
SET @ArchiveName = ?
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name =
@ArchiveName)
BEGIN
EXEC ('DROP DATABASE' + @ArchiveName)
END
And this:

IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name =
?)
BEGIN
EXEC ('DROP DATABASE' + ?)
END
Please let me know if you know how to make it work
Thanks a lot
Irene



Reply With Quote
  #3  
Old   
Irene
 
Posts: n/a

Default Re: Passing database name as a parameter to execute SQL task - 11-21-2006 , 03:22 PM



Hi Allan,
It works! Thank you very much
Irene

"""Allan Mitchell ΠΙΣΑΜ(Α):
"""
Quote:
Hello Irene,


Have a look at this article to see how to accomplish this

http://www.sqldts.com/default.aspx?205


Regards

Allan Mitchell
Konesans Ltd
T +44 7966 476 572
F +44 2071 008 479
http://www.konesans.com

Hi there,
I am using DTS script for the conversion. I would like to get a
database name as a parameter from the user (through a command line),
assign it to the package global variable, and then use Execute SQL
task
to drop and recreate a database with such name. However, I have
troubles passing a parameter to Execute SQL task.
The following syntax works:
DECLARE @ArchiveName VARCHAR
SET @ArchiveName = 'Conversion'
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name =
@ArchiveName)
BEGIN
EXEC ('DROP DATABASE' + @ArchiveName)
END
However, I need @ArchiveName to be a parameter set by user. Any
attemts to use parameters in Execute SQl task throw error:

DECLARE @ArchiveName VARCHAR
SET @ArchiveName = ?
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name =
@ArchiveName)
BEGIN
EXEC ('DROP DATABASE' + @ArchiveName)
END
And this:

IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name =
?)
BEGIN
EXEC ('DROP DATABASE' + ?)
END
Please let me know if you know how to make it work
Thanks a lot
Irene


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.