SQL Command text with parameter OLEDB Source - sql

I am working with SQL Server Integration Services 2008. In my Data Flow task I got a OLEDB source. I choose SQL command as the Data Access mode and following is my sql text
Select * from table1 where ID=?
And from parameters tab my Parameter Name is zero "0" and value is coming from a package level variable.
I tried to replace the parameter name with "Parameter0" but I always get the same error that
Error: "No Value given for one or more required parameters"
But there is a value for my variable

You are doing the right thing, but it is the "Preview" that is not working for parameterized source tasks. Try executing the package and you should be ok.

Related

The SQL command requires a parameter named "#SessionID", which is not found in the parameter mapping

I'm trying to execute a stored procedure via SSIS
Error: 0xC0207014 at PO Header, OLE DB Source [59]: The SQL command
requires a parameter named "#SessionID", which is not found in the
parameter mapping.
But as you can see below, the variables are populated, I have mapped the parameters.
So what's going on?
MS SQL 2014
MS Visual Studio 2015
Based on the screenshots, you have mapped variables to parameters. Then just try to delete and recreate the OLE DB Source.
The SQL command requires a parameter, which is not found in the parameter mapping
If it still throwing an error, then use expressions instead of parameters. You can refer to the following link for more information:
Unable to pass a variable value to a stored procedure in ssis
I was having the same issue and even having Visual Studio crash on me. I found that rather than using parameter index of 0,1, 2... I used named parameters in my OLEDB connect and this resolved my error. You must include the # in the parameter name and they must match your sql stored procedure parameter names.
For example instead of [0] and [1] name parameters #StartDate and #EndDate

Declare SQL construct or statement is not supported for simple query

I have simple SQL Query and need to get the input from parameter. I am getting the when i click parameter button. Please let me know how to get the parameter if i have declare statement in my scripts.
Note :OLEDB connection manager used for connection
You can't use parameters in an OLEDB Source if your command contains DECLARE, or anything other than a single SELECT statement.
The way to do what you want is to use build your entire SQL Command into a single SSIS variable, and use the "SQL Command from variable" option in the OLEDB source.
EDIT based on comments:
If you have to handle a SQL Command over 4000 characters, the only way to do it is in a Script Component. The SQL Command in a script component can be any length. Here is an example.

SSIS Variable Date Failing between SQL Server and ORACLE

Good Afternoon All,
I have spent about 6 hours trying to get formatting to work through SSIS using a Max Date Variable to identify into a where clause - Just have no luck!
I have created a variable called my_date which fetched the Max(Date) from a local SQL server table to understand the last load point for that table - using the below code:
SELECT CAST(FORMAT(MAX(Business_Date), 'dd-MMM-yyyy') AS varchar) AS my_date FROM Table
This fetches the date correctly as 17-Sep-2018.
I have then mapped my result set as my_date -> User::max_date
I have set my max_date variable to a string data type under the package scope.
I have tested my variable out by using breakpoints to ensure this runs all the way through in the correct format - and this works 100%.
I then have a data flow task running to fetch data from my ORACLE DB to insert into my SQL Server table which contains the following SQL command:
SELECT *
FROM Table2
WHERE (BUSINESS_DATE > to_date('#[User::max_date]', 'DD-MON-YYYY'))
However I get the ORA-01858 - [TABLE] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E07.
An OLE DB record is available. Source: "Microsoft OLE DB Provider for Oracle" Hresult: 0x80040E07 Description: "ORA-01858: a non-numeric character was found where a numeric was expected
".
If I go and replace my variable directly with the contents of the variable shown by the breakpoint in locales it works perfectly!
I have attempted multiple format types from the initial export through to the final where clause and this seems to be the closest I have come to pushing it through but it is still complaining about format.
Please help - Images below to help see setup.
Control Flow - displaying the execute SQL and the data flow task
Locale showing Variable is inserting after breakpoint is reached
Managed to get it working!
By adding an intermediary variable where the value and expression contains the following:
"SELECT *
FROM TABLE
WHERE (BUSINESS_DATE > to_date('"+#[User::max_date]+"' , 'DD-MON-YYYY'))"
I then amended my source OLEDB to SQL Command from variable and selected the above variable created and it worked perfectly!
Try mapping your user parameter in the "OLE DB Data Source Editor", under "Parameters".
1) Change SQL Command Text (change #[User::max_date] to ?), like this:
SELECT *
FROM Table2
WHERE (BUSINESS_DATE > to_date('?', 'DD-MON-YYYY'))
2) Then in the parameter editor, map parameter 1 to #[User::max_date].
https://learn.microsoft.com/en-us/sql/integration-services/data-flow/map-query-parameters-to-variables-in-a-data-flow-component?view=sql-server-2017
Also, the "Oracle Provider for OLE DB" behaves differently than the "Microsoft OLE DB Provider for Oracle", so it depends which you are using.

Execute SQL Task fails in SSIS 2008 package but runs successfully outside package

I created an execute sql task to save the filenames encountered in a Foreach Loop task into a database table,
this works fine when I run the the individual task and it writes the filename to the database table (see below)
UNABLE TO POST IMAGES CURRENTLY
![task successfully runs][1]
However when i run the complete SSIS package, this task fails (see below)
UNABLE TO POST IMAGES CURRENTLY
![unsuccessful execution][2]
The error message I am getting is:
Error: String or binary data would be truncated.
[Execute SQL Task] Error: Executing the query "insert into filename_staging_table
(FileName) Val..." failed with the following error:
"The statement has been terminated.". Possible
failure reasons: Problems with the query,
"ResultSet" property not set correctly, parameters
not set correctly,
or connection not established correctly.
Any guidance with this greatly appreciated....I am completely stuck!!!!
Thanks
The error reads "String or binary data would be truncated." The reason the script works when run manualy is because you are only trying to insert one value. That value is within the length constraint of your column.
When you run the task, it is looping through a list of filenames and trying to insert each one. One of these names is too long for the field you are trying to insert it into.
You need to change the length of the field in SQL or you need to use a LEFT(filename, xx) on the filename itself so that a only the first xx characters are inserted into your table. (Change the xx to the number of characters to be inserted)

How do I pass system variable value to the SQL statement in Execute SQL task?

SSIS 2008. Very simple task. I want to retrieve a System Variable and use it in an SQL INSERT. I want to retrieve the value of System:MachineName and use it in an insert statement.
Using the statement INSERT INTO MYLOG (COL1) SELECT #[System::MachineName] gives the error Error: ..failed to parse. Must declare the scalar variable "#"
Using the statements SELECT #System::MachineName or SELECT ##[System::MachineName] gives the error 'Error Incorrect systax near '::'
I am not trying to pass a parameter to the query. I have searched for a day already but couldn't find how to do this one simple thing!
Here is one way you can do this. The following sample package was created using SSIS 2008 R2 and uses SQL Server 2008 R2 as backend.
Create a sample table in your SQLServer database named dbo.PackageData
Create an SSIS package.
On the SSIS, add an OLE DB connection manager named SQLServer to connect to your database, say to an SQL Server database.
On the Control flow tab, drag and drop an Execute SQL Task
Double-click on the Execute SQL task to bring the Execute SQL Task Editor.
On the General tab of the editor, set the Connection property to your connection manager named SQLServer.
In the property SQLStatement, enter the insert statement INSERT INTO dbo.PackageData (PackageName) VALUES (?)
On the Parameter Mapping tab, click Add button, select the Package variable that you would like to use. Change the data type accordingly. This example is going to insert the PackageName into a table, so the Data Type would be VARCHAR. Set the Parameter Name to 0, which indicates the index value of the parameter. Click OK button.
Execute the package.
You will notice a new record inserted into the table. I retained the package name as Package. That's why the table
Hope that helps.
Per my comment against #ZERO's answer (repeated here as an answer so it isn't overlooked by SSIS newcomers).
The OP's question is pretty much the use case for SSIS property expressions.
To pass SSIS variables into the query string one would concatenate it into an expression set for the SqlStatementSource property:
"INSERT INTO MYLOG (COL1) SELECT " + #[System::MachineName]
This is not to suggest the accepted answer isn't a good pattern, as in general, the parameterised approach is safer (against SQL injection) and faster (on re-use) than direct query string manipulation. But for a system variable (as opposed to a user-entered string) this solution should be safe from SQL injection, and this will be roughly as fast or faster than a parameterised query if re-used (as the machine name isn't changing).
I never use it before but maybe you can check out the use of expression in Execute SQL task for that.
Or just put the whole query into an expression of a variable with evaluateAsExpression set to true. Then use OLE DB to do you insert
Along with #user756519's answer, Depending on your connection string, your variable names and SQLStatementSource Changes