I am trying to assign the same package variable value to three different parameters in a query. The variable contains the name of a database which the user will input during package execution. First I check to see if the database exists (if it does I drop it), then in either case I create the database. See code:
if
exists ( select name from sys.databases where name = ) begin drop database ; end;go
create
database ;go
This is the error I am getting:
[Execute SQL Task] Error: Executing the query "if exists ( select name from sys.databases where name = ) begin drop database ; end; " failed with the following error: "Syntax error, permission violation, or other nonspecific error". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
My "User::DestinationDatabase" variable is mapped to 0,1,2 using an OLE DB connection. Any suggestions would be welcome.
Regards,
DO

Parameter Mapping in an Execute SQL Task
Cybergenius
DOMcCrea
George Neo
Soumyp
And if you do do that, the 2 new variables that you create only have to be made equal to the first variable by using expressions.
-Jamie
PMNJ
A couple of points. DROP DATABASE can't take a variable the database name.
Secondly I don't think that you can use paramaters in the execute sql task with a sql statement only an SP.
For this reason if you want to execute a sql statement you need to build it up in an expression and then execute that
Echo
They both achieve the same thing. It is of course your choice which you choose. I would always choose expressions because:
1) Less coding to do
2) Less work for the package to do (i.e. less tasks in your control flow)
3) Expressions use out-of-the-box functionality. Scripts are more of a workaround.
4) The expression is evaluated when the variable is called. If you go the script task route you have to make sure that the value is explicitly changed prior to calling it. Hence I think expressions are more intuitive and easier to be understood by a person who has to understand your package later.
-Jamie
techme
Bathisar
Ryan Sun
Thanks. I did not know that you can not use a parameter for a DDL statement. I tried to create a DB, table, view....nothing worked. I guess my options are to use dynamic SQL within the Execute SQL Task, pass the query in a variable, or a Script Task that makes a connection, checks for the db, etc. With regard to your second point, you can use parameters in a SQL query within an Execute SQL Task. However, it only seems to work with very simple queries i.e. select * from table where column = . Anything more creative than that seems to throw it for a loop. I am probably going to try the SQL query in a variable method. Let me know if you think of anything else. Thanks again for your post.
=== Edited by DatabaseOgre @ 10 Mar 2006 10:54 PM UTC===
I ended up using the SQL query in a variable method and it worked. Kudos to Jamie, I used one of his other posts to figure it out.
R3dD0g
Ken Holcombe
Wowbagger_TIP