SSIS Execute SQL Task Error using Parameters - sql

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')

Related

Create table name using username in Hive query running in Oozie workflow?

I've got a Hive SQL script/action as part of an Oozie workflow. I'm doing a CREATE TABLE AS SELECT to output the results. I want to name the table using the username plus an appended string (e.g. "User123456_output_table"), but can't seem to get the correct syntax.
set tablename=${hivevar:current_user()};
CREATE TABLE `${hiveconf:tablename}_output_table` AS SELECT ...
That doesn't work and gives:
Error while compiling statement: FAILED: IllegalArgumentException java.net.URISyntaxException: Relative path in absolute URI: ${hivevar:current_user()%7D_output_table
Or changing the first line to set tablename=${current_user()}; starts running the SELECT query but eventually stops with:
Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. org.apache.hadoop.hive.ql.metadata.HiveException: [${current_user()}_output_table]: is not a valid table name
Or changing the first line to set tablename=current_user(); starts running the SELECT query but eventually stops with:
Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. org.apache.hadoop.hive.ql.metadata.HiveException: [current_user()_output_table]: is not a valid table name
Alternatively, is there a way to pass the username from the Oozie workflow via a parameter?
I'm using Hue to do all this rather than the command line.
Thanks
This is wrong: set tablename=${hivevar:current_user()}; - it will not be resolved and substituted as is.
Hive does not calculate variables before substitution, it substitutes them as is, all functions in variables are NOT calculated. variables are just text replacement.
This:
set tablename=current_user();
CREATE TABLE `${hiveconf:tablename}_output_table` ...
gets resolved as
CREATE TABLE `current_user()_output_table` ...
And functions are not supported in table names, it will not work this way.
The solution is to calculate functions outside the script and pass them as parameters.
See this blog: https://prodlife.wordpress.com/2013/12/06/parameterizing-hive-actions-in-oozie-workflows/

SQL query using Firebird and foreign characters causes a malformed string error

I have a simple example that is causing an error using Firebird SQL.
I have a table with a column called Details which is defined as:
DETAILS varchar(261) COLLATE UNICODE
If I try to do the following query:
SELECT a.DETAILS
FROM MODHISTORY a
WHERE
a.DETAILS LIKE '%Â%'
I get the error:
Error: *** IBPP::SQLException ***
Context: Statement::Prepare( SELECT a.DETAILS
FROM MODHISTORY a
WHERE
a.DETAILS LIKE '%Â%'
)
Message: isc_dsql_prepare failed
SQL Message : -104
Invalid token
Engine Code : 335544849
Engine Message :
Malformed string
If I connect to the database using CHARSET=UTF8 in the connection string this error goes away but unfortunately I cannot use UTF8 as the character set when connecting to the database because some other tables contain, for example:
SampleData blob sub_type 1 CHARACTER SET ASCII,
I have solved my problem as suggested. I am binding the parameters and now everything works fine

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

Initialize / activate SQL prior to GET DIAGNOSTICS

I have two service programs: mySrvPgm and myErr
mySrvPgm has a procedure which contains:
/free
...
exec sql INSERT INTO TABLE VALUES(:RECORD_FMT);
if sqlError() = *ON;
//handle error
endif;
...
/end-free
myErr has a procedure sqlError:
/free
exec sql GET DIAGNOSTICS CONDITION 1
:state = RETURNED_SQLSTATE;
...
/end-free
Background info: I am using XMLSERVICE to call the given procedure in mySrvPgm from PHP. I am not using a persistent connection. myErr is bound-by-reference via a binding directory used by mySrvPgm. Its activation is set to *IMMED, its activation group is set to *CALLER.
The problem: Assume there is an error on the INSERT statement in mySvrPgm. The first time sqlError() is called it will return SQLSTATE 00000 despite the error. All subsequent calls to sqlError() return the expected SQLSTATE.
A workaround: I added a procedure to myErr called initSQL:
/free
exec sql SET SCHEMA MYLIB;
/end-free
If I call initSQL() before the INSERT statement in mySrvPgm, sqlError() functions correctly. It doesn't have to be SET SCHEMA, it can be another GET DIAGNOSTICS statement. However, if it does not contain an executable SQL statement it does not help.
The question: I believe the myErr service program is activating properly and has the correct scope, but I am wondering if there is something more I need to do to activate the SQL part of it. Is there some way to set it up so SQL auto-initializes when the service program is activated, or do I have to execute an unneeded SQL statement in order to get it started?
There is some more background information available here.
Thank you for reading.
What version an release of the OS? Are you upto date on PTFs?
Honestly, seems to me that it's possibly a bug. Or the manual(s) need clarification.. I'd open a PMR.

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