I'm fairly new to SSIS and don't know all it's features and what tasks I can use to do things I want. I have found many Google and stackoverflow.com searches to help me get to know variables and parameters and how to set them etc.
BLUF (Bottom Line Up Front)
I have a view
with data which I want to export to a file through a job that runs the package.
The data will be filtered by it's LastUpdatedDate
field with datatype of DateTimeOffSet(7)
. The package should allow a user to run it with a specified dat or use a value from another table (SSISJobRun
).
Structure
/*Employee Table*/
Id int
Name varchar(255)
LastUpdatedDate datetimeoffset(7)
/*SSISJobRun Table*/
Id int
JobTypeId int
RunDate datetimeoffset(7)
What I have Done
Currently, I'm using SSDT for VS 2015 to create my SSIS packages and deploy them to my SSIS Catalog.
I have a project with 1 package. The package contains:
- a
Data Flow Task
namedEmployeeExport
; this task contains anOLE DB Source
and aFlat File Destination
- a package level parameter named Filename_Export (this is so that the file path can be changed when it's run by a user; the parameter has a default value configured within the Job that runs it daily
All this runs perfectly fine.
Problem
I also have set another package level parameter named LastUpdatedDate
. The intent is to have who/what-ever runs the package to define a date. However, if the date is null
(if I decide to use a string
) or if the date is the default value 1899-12-30 00:00:00
(if I decide to use a date
), I want to determine what date to use.
Specifically, if there is no real date supplied by the user, then I want to the date to be the latest RunDate
. For that case I use the following code:
SELECT TOP 1 LastUpdatedDate
FROM SSISJobRun
WHERE JobTypeId = 1
ORDER BY LastUpdatedDate DESC
I've tried many different ways, and it works when I supply a date, but I couldn't get it to work when the date I gave was blank when I used a string or the default when I used a date.
Here's a few sources I've been looking through to figure out my issue
- How to pass SSIS variables in ODBC SQLCommand expression?
- How do I pass system variable value to the SQL statement in Execute SQL task?
- http://mindmajix.com/ssis/how-to-execute-stored-procedure-in-ssis-execute-sql-task
.. and many more.
Once last note: this date
will be used to run two tasks, so if there is a way to keep it global that would be great.
Lastly, I need to package to insert a row specifying when the the task was run into the SSISJobRun
table.
Thank you.