0

I want to generate dynamically excel file using SSIS package. I tried like following :

In data flow task I have taken Oledb Source inside oledb source editor under connection manager taken data access mode = sql command from variable as my variable is having sql query like below select cusip,price,company from mytable where date in between @[var1] and @[var2]

But i failed to use var1 and var 2 it is giving me parse error.

created 3 variables inside ssis project

var1 datatype = datetime value=5/01/2011 8:22:10 AM

var2 datatype = datetime value=5/21/2011 8:22:10 AM

var3 datatype = datetime value=MY ABOVE SELECT QUERY Using above select query I want to generate new excel file every day with filename like MYFile05222013 (with yesterdays date)

var 3 taken as string and added value into Expression But getting parse error :

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 "@".".

AND

The data types "DT_WSTR" and "DT_DATE" are incompatible for binary operator "+". The operand types could not be implicitly cast into compatible types for the operation. To perform this operation, one or both operands need to be explicitly cast with a cast operator.

Please advice.

enter image description here

1 Answer 1

1

Try making var3 a string datatype (not a datetime). Give it an expression like this:

"select cusip,price,company from mytable where date in between " + @[User::var1] + " and " + @[User::var2]

Make the var1 and var2 variables string datatypes, also. Set up var1 and var2 with default values that parse to valid datetime values.

To view the evaluation result of the expression, click Evaluate Expression in the Expression Builder.

For the output file, you will want an Excel Destination. The destination connection manager will have an expression for the filename. That expression is where you will build a filename like "MYFile05222013".

Sign up to request clarification or add additional context in comments.

9 Comments

I want to set up @var2 dynamically to previous date how can i do so? please help
Use GETDATE in an expression for var2. You'll need to convert it to a string at some point to build your select query. Have you fixed the parse error in your Oledb Source yet?
No I'm getting same error again : 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 "@".".
Also Getting error : ` The data types "DT_WSTR" and "DT_DATE" are incompatible for binary operator "+". The operand types could not be implicitly cast into compatible types for the operation. To perform this operation, one or both operands need to be explicitly cast with a cast operator.`
You set it in static string rather than an expression. Probably best to get rid of var3, and use var1 and var2 in an OLD DB Source Parametrized SQL Statement like "SELECT * FROM Production.Product WHERE Color = ? AND Size = ?"
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.