jim
jim

Reputation: 1116

SSIS Extra quotes added in my Execute sql task

I have a global string variable that stores a table name and I would like to use this variable inside of a Execute SQL Task when I'm writing a query.

The query I have in the Execute SQL Task is: CREATE TABLE ?

This is supposed to create a table inside the Netezza system which is where my OLEDB is connected to. (The connection is successful)

The problem that I'm getting when I look at the output is: ERROR: 'CREATE TABLE 'TableName'' Expecting an identifier found a "keyword".

As you can see, it adds quotations around my table name which is stored in a variable. Inside the parameter mapping I add my variable with direction =>input, data type => nvarchar, parameter name=> 0 and parameter size => 0. How can I access the value of the variable without the quotations?

Upvotes: 1

Views: 749

Answers (1)

Thom A
Thom A

Reputation: 95589

The ? is like a variable in SQL Server. You can't do syntax like the following in SQL Server:

DECLARE @Table sysname = N'YourTable';
SELECT *
FROM @Table;

You need to create a second variable in your SSIS package, and set the expression to be:

"CREATE TABLE " + {Your Variable} + "..."

(Obviously replace {Your Variable} with your variable's full name. For example @[User::TableName])

You'll then need to change the value of SQLSourceType to Variable and select your new variable in the SourceVariable dropdown.

Upvotes: 1

Related Questions