Dynamically Passing Table Names - using SQL Command from Variable - variables

I read this thread: SSIS : Dynamically passing Table names and this is exactly what I'm trying to achieve. I got to the point of creating the string variable.
However, in the OLEdb source editor, when I chose to use SQL Command from Variable, the preview gave the following error prompt:
Exception from HRESULT: 0xC0202009
Error at Data Flow Task [OLE DB Source [37]]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E14.
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80040E14 Description: "Statement(s) could not be prepared.".
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80040E14 Description: "Must declare the table variable "#".".
Appreciate some help on what could be the issue here.
Below are the components that I have set up.
EXECUTE SQL TASK:
SELECT name from sys.tables WHERE name like'%$Company Information'Order by name
Result Set: Variable Name = User::IndivTableName; Result Name = 0; Data Type=Object
For Each Loop Container:
Enumerator: Foreach ADO Enumerator
ADO Object source variable: User::IndivTableName
Enumeration mode: Rows in the first table
(Is this needed?) Variable mappings: Variable = User::IndivTable; Index=0; Data Type = Object
String Variable:
Variable Name: User::CompanyInformation
Expression:
"select [name],[address],[address 2],[city],[phone no_],[fax no_],
[VAT Registration no_],[registration no_],[business type] from " + "#[User::IndivTableName] "
Evaluated Value:
select [name],[address],[address 2],[city],[phone no_],[fax no_],
[VAT Registration no_],[registration no_],[business type] from #[User::IndivTableName]
Data Source Editor:
Data Access Mode: SQL command from variable
Variable Name: User::CompanyInformation
Variable Value:
select [name],[address],[address 2],[city],[phone no_],[fax no_],
[VAT Registration no_],[registration no_],[business type] from #[User::IndivTableName]

Variable mappings at ForEach ADO Enumerator are mandatory, your mappings are ok. Please change datatype of User::IndivTable variable to string.
Change Variable 'User::CompanyInformation' expression to
"select [name],[address],[address 2],[city],[phone no_],[fax no_],
[VAT Registration no_],[registration no_],[business type] from " + [User::IndivTable]
Variable User::IndivTableName contains DataTable, so it cannot be used in expression. You iterate over it and store the first column into User::IndivTable variable.

Related

(DECIMAL)Conversion failed because the data value overflowed the specified type

Everything runs fine, just error in the OLE DB destination, Error said its conversion failed and i also try to convert the ProjectedROI but convert failed. so i check the source sqlcommand the output is correct
then i try to see check the output or the data passing thro the source and i see that the format of the output is not same with the destination column ProjectedROI which is decimal(2,2)
below are error messages:
[Insert New Record to Fact_Sales [162]] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E21.
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80040E21 Description: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.".
[Insert New Record to Fact_Sales [162]] Error: There was an error with Insert New Record to Fact_Sales.Inputs[OLE DB Destination Input].Columns[ProjectedROI] on Insert New Record to Fact_Sales.Inputs[OLE DB Destination Input]. The column status returned was: "Conversion failed because the data value overflowed the specified type.".
[Insert New Record to Fact_Sales [162]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "Insert New Record to Fact_Sales.Inputs[OLE DB Destination Input]" failed because error code 0xC020907A occurred, and the error row disposition on "Insert New Record to Fact_Sales.Inputs[OLE DB Destination Input]" specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure.
[SSIS.Pipeline] Error: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "Insert New Record to Fact_Sales" (162) failed with error code 0xC0209029 while processing input "OLE DB Destination Input" (175). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure.
You have a lot of steps between your source and destination and you haven't shown what the data looks like after each one. At some point, your data is going from Decimal(2,2) to something like Decimal(14,11) if I am counting right.
Starting with the source and going to each step after until you find the culprit, right click on each component and open advanced properties, and look at the datatype of the output column ProjectedROI. Verify it has the correct Precision and Scale.

Unable to pass a variable value to a stored procedure in ssis

When executing an SSIS package, the following error appears:
[OLE DB Source [83]] Error: The SQL command requires a parameter named
"#Sales_person", which is not found in the parameter mapping.
[SSIS.Pipeline] Error: OLE DB Source failed the pre-execute phase and
returned error code 0xC0207014.
Below is the screenshot of my OLE DB Source editor
I do see Param direction tab in Set Query parameters, how is that used? In my case will I be using Input or Output or InputOutput
After searching i didn't find a solution for this issue that worked for me. Ther are many suggestions like adding SET NOCOUNT ON before the execute command. Below some related links:
http://geekswithblogs.net/stun/archive/2009/03/05/mapping-stored-procedure-parameters-in-ssis-ole-db-source-editor.aspx
http://www.sqlservercentral.com/articles/Data+Flow+Task+(SSIS)/117370/
http://www.ssistalk.com/2007/10/10/ssis-stored-procedures-and-the-ole-db-source/
You can do a workaround
Declare a SSIS variable (assuming #[User::Query])
Set #[User::Query] property EvaluateAsExpression = True and use the following expression
"EXEC [dbo].[GetDales_Person_data] " + #[User::Sales]
if #[User::Sales] is a string use the following
"EXEC [dbo].[GetDales_Person_data] '" + #[User::Sales] + "'"
Then In OLEDB Source use SQL Command from variable and select #[User::Query]
The problem is with the mapping. See image and source below to make corrections, you should set it to:
Exec [dbo].[GetSales_Person_Data] #Sales_person = ?
Source - geek with blogs
There seems to be a problem with mapping parameters directly into the EXEC statement.
One way you can get around this is to use:
DECLARE #SalesPerson int = ? -- or whatever datatype
EXEC [dbo].[GetSales_Person_Data] #SalesPerson

Connection String for dynamic OLE DB Destination in SSDT/SSIS for SQLServer2014

I am new to SQL Server, but not SQL or programming in general. I have been reading the online documentation and tutorials available to set up a For each loop within SSDT/SSIS that loops through a series of flat files in a folder and creates a DB object for each with the same name.
The loop works, except setting up the Connection String for OLE DB Destination Manager. My Server is called 'OLEGS_LAPTOP' with a database called 'Football Data' and I am using the following Connection String:
"Provider=SQLNCLI11.0;Server=OLEGS_LAPTOP;Source=(local);Initial Catalog="+ #[User::FileFound] + "Football Data"+";Integrated Security=SSPI;Auto Translate=False;"
Here, #[User::FileFound] represents the variable set up in the Flat File Connection Manager for looping through the files in my chosen local folder. When I try using this Connection String for the OLE DB object, I get the following error:
TITLE: Package Validation Error
------------------------------
Package Validation Error
------------------------------
ADDITIONAL INFORMATION:
Error at Data Flow Task [OLE DB Destination [10]]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80004005 Description: "Unspecified error".
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80004005 Description: "The metadata could not be determined because every code path results in an error; see previous errors for some of these.".
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80004005 Description: "Invalid object name 'dbo.OLE DB Destination'.".
Error at Data Flow Task [OLE DB Destination [10]]: Failed to open a fastload rowset for "[dbo].[OLE DB Destination]". Check that the object exists in the database.
Error at Data Flow Task [SSIS.Pipeline]: "OLE DB Destination" failed validation and returned validation status "VS_ISBROKEN".
Error at Data Flow Task [SSIS.Pipeline]: One or more component failed validation.
Error at Data Flow Task: There were errors during task validation.
(Microsoft.DataTransformationServices.VsIntegration)
------------------------------
BUTTONS:
OK
------------------------------
Can anyone tell me what I need to change in my string to get the desired result?
Thanks
Further to answers/support given so far:
The error message I am now receiving is:
TITLE: Package Validation Error
------------------------------
Package Validation Error
------------------------------
ADDITIONAL INFORMATION:
Error at Data Flow Task [OLE DB Destination [10]]: A destination table name has not been provided.
Error at Data Flow Task [SSIS.Pipeline]: "OLE DB Destination" failed validation and returned validation status "VS_ISBROKEN".
Error at Data Flow Task [SSIS.Pipeline]: One or more component failed validation.
Error at Data Flow Task: There were errors during task validation.
(Microsoft.DataTransformationServices.VsIntegration)
------------------------------
BUTTONS:
OK
------------------------------
It looks like somehow the string "OLE DB Destination" got into table\view mapping (first screenshot) and [dbo].[OLE DB Destination] came out as a table name. Perhaps you've replaced table name with this string in the OpenRowset property of the OLE DB Destination properties window (second screenshot).
LATER EDIT
In order to be able to get table name from variable (assume that you have such variable with table name assigned to it) you need to change your OLE DB Destination's AccessMode property to OpenRowset From Variable and specify variable name in the OpenRowsetVariable property (see image below)

SSIS Execute SQL Task Error using Parameters

SSIS 2012....I want to post a success message to a SQL table in the same DB where I'm working. I created a variable called "InputRowCount" as Int32, and set it in the RowCount transform. Then, in a SQL Task, I set it as an input parameter, incidentally giving it a name. My DB connection is OLEDB, so the book says I just use a "?" to reference the lone Parameter (I expect to insert more parameters later....) It gets a "Parameter name is unrecognized" error. Here's the SQL Statement:
[Edit...now I get that the parameter type cannot be deduced...]
[Execute SQL Task] Error: Executing the query "INSERT INTO dbo.tblpendingmessages
([Recipi..." failed with the following error: "The parameter type for '#P1' cannot be uniquely deduced; two possibilities are 'float' and 'datetimeoffset(7)'.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
INSERT INTO dbo.tblpendingmessages
([Recipient]
,[MessageSubject]
,[MessageBody]
,[MessageGenerated]
,[MessageUser]
,[MessageFormat])
VALUES
(N'CPAS_Administrator#xxxxxx.COM' -- Recipient
,N'All Projects Import' -- Subject Line
,N'ALL Projects Import has replaced ' + FORMAT(?,'N','en-us') + N' rows of the AllProjects Table in CPAS.' -- MessageBody
,GETDATE() -- MessageGenerated
,N'SSIS'
,N'TEXT')

Paramaterising SQL in SSIS

I'm trying to paramaterize some queries in SSIS. After some reading, it sounds like my best option is to create one variable that contains my base sql, another that contains my criteria and a final variable that is evaluated as an expression that includes both of these. I want to end up with an SQL query that is effectively
UPDATE mytable set something='bar' where something_else='foo'
So my first two variables have the scope of my package and are as follows:
Name: BaseSQL
Data Type: String
Value: UPDATE mytable set something = 'bar' where something_else =
Name: MyVariable
Data Type: String
Value: foo
My third variable has a scope of the data flow task where I want to use this SQL and is as follows:
Name: SQLQuery
Data Type: String
Value: #[User::BaseSQL] + "'" + #[User::MyVariable] + "'"
EvaluateAsExpression: True
In the OLE DB Source, I then choose my connection and 'SQL command from variable' and select User::SQLQuery from the dropdown box. The Variable Value window then displays the following:
#[User::BaseSQL] + "'" + #[User::MyVariable] + "'"
This is as desired, and would provide the output I want from my DB.
The variable name dropdown also contains User::BaseSQL and User::MyVariable so I believe that my namespaces are correct.
However, when I then click preview, I get the following error when configuring an OLE DB Source (using SQL command from variable):
TITLE: Microsoft Visual Studio
Error at Set runtime in DB [Set runtime in myDb DB [1]]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E14.
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80040E14 Description: "Statement(s) could not be prepared.".
An OLE DB record is available. Source: "Microsoft SQL Server Native Client 10.0" Hresult: 0x80040E14 Description: "Must declare the scalar variable "#".".
(Microsoft Visual Studio)
Can anyone advise what I'm missing or how I can resolve this please ?
Thanks in advance!
I had a similar issue.
It seems to be that the designer wants something at design time.
I was getting the error when i tried to click OK on the oleDBSource task after choosing a variable name.
I had a similar situation where the where clause logic was a bit involved and required a script task to assign its value.
This is what things looked like at design time.
#basesql = "select from mytable where "
#where = empty string
#fullsql = #basesql + #where
i was getting the E14 error you mentioned above.
by changing the design time value of #where to something silly, the oleDBSource task got what it wanted and let me use the variable.
#where = " value1 is null and value2 = 'easteregg' "
Related issue, to even get the thing to work, i had to start out by putting a basic select stmt into the sql command so it could go get source columns.
It makes sense, but that step took me and google a while to figure out.
You should set the Expression property of SQLQuery, instead of the Value property. If you do it correctly, the Variable Value window should show you the result of the expression:
UPDATE mytable set something = 'bar' where something_else = 'foo'
I would create a script task and concatenate the strings into one variable and use that as your source:
Dts.Variables["SQLQuery"].Value = Dts.Variables["BaseSQL"].Value.ToString() +
Dts.Variables["MyVariable"].Value.ToString();
Then, in the advanced properties under the component properties tab, you need to change the ValidateExternalMetadad property to False so SSIS will not try to prevalidate your sql query in your variable which would give you a run time error. Just created a simple package and that seemed to work. Hope this helps.
-Ryan