0

I keep getting an unexplainable error (see below) when I try to run a simple query in SSIS' OLEDB Command.

My query runs just fine in SQL Server, I made some adjustments to make it simpler to ensure it runs, but to no avail.

DECLARE @Gender [nvarchar](6)
DECLARE @Ready [nvarchar](12)
DECLARE @DOB [datetime]

SET @Gender=?
SET @Ready=?
SET @DOB=?


IF @Gender = 'M'
    SET @Gender='Male'
IF  @Gender = 'F'
    SET @Gender='Female'
IF @Ready='Y'
    SET @DOB=NULL

INSERT INTO [dbo].[PHI_CLIENT_PROFILES]
([col43],
[col13],
[col22],
[col10],
[origin]
)
VALUES
(@DOB, @Gender, ?, ?, ?)

ERROR MESSAGE:

Validation error. Data Flow Task: Data Flow Task: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005. An OLE DB record is available. Source: "Microsoft OLE DB Provider for SQL Server" Hresult: 0x80004005 Description: "Syntax error or access violation"

8
  • 1
    Are you providing 7 variables on the parameter mapping tab?
    – billinkc
    Feb 27, 2017 at 20:17
  • @billinkc no I am not because of that error, the param page will NOT refresh. I tried 100 different varaitions, and added/removed my code line by line so the param page is outdated (it shows 1 param because of my line by line approach). Previous to breaking the code, the param page wouldn't show anything Feb 27, 2017 at 20:21
  • @billinkc I should also add that the issue seems to be over the variable part. Does SSIS OLEDB COMMAN accept variables? I tried a simpler code and it worked, but I'm quite new to this task. Feb 27, 2017 at 20:22
  • I would start by replacing all parameters by actual values and see if this executes, then restore them one-by-one, to see if it is a specific parameter which creates the problem. Feb 27, 2017 at 20:30
  • @GiorgosAltanis Thanks for the advice. I did just that , but unfortuantely the only way it'd work is to get rid of ALL DECLAREs and SETs. I am fairly sure I had used DECLARE/SET before in a simpler case though - but it doesn't work here for some reason Feb 27, 2017 at 20:36

1 Answer 1

3

I don't know what you are intending there, but unless you need the inserted identities or calling some legacy function, there is no need for the OLE DB Command. Using this transformation for executing only SQL insert statements to a single table should be avoided as it will execute each row as separate batch. Try a destination component instead.

Add a derived column component and use built-in expression functionality. Example:

DerivedGender :    
    [Gender] == "M" ? "Male" : "Female"
DerivedDOB :
    [Ready] == "Y" ? NULL(DT_DBTIMESTAMP) : [DOB]
...

After doing the transformation, use an OLE DB destination component.

In some cases, it might be worth to check whether the Foreach Loop Container can solve the task.

3
  • Thank you so much - I was actually unaware of the use of this task. Feb 28, 2017 at 13:17
  • Just one thing though, your case is inaccurate: If Gender is M then Male, if Gender is F then female (there is no else), how could you express that?? Thank you Feb 28, 2017 at 13:24
  • 1
    [Gender] == "M" ? "Male" : [Gender] == "F" ? "Female" : "Invalid"
    – Raul
    Feb 28, 2017 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.