Your intention is to retrieve the values of start and end and assign those into SSIS variables.
As @Diego noted above, those two SELECTS are going to cause trouble. With the Execute SQL task, your resultset options are None, Single Row, Full resultset and XML. Discarding the XML option because I don't want to deal with it and None because we want rows back, our options are Single or Full. We could use Full, but then we'd need to return values of the same data type and then the processing gets much more complicated.
By process of elimination, that leads us to using a resultset of Single Row.
Query aka SQLStatement
I corrected the supplied query by simply removing the two aforementioned SELECTS. The final select can be simplified to the following (no need to put them into derived tables)
SELECT
CONVERT(Varchar(11),@VarStartDateTime,106) AS VarStartDateTime
, CONVERT(Varchar(11),@VarENDDateTime,106) AS VarENDDateTime
Full query used below
declare @VarExpiredDays int
-- I HARDCODED THIS
Select @VarExpiredDays= 10
DECLARE @VarENDDateTime datetime,@VarStartDateTime datetime
SET @VarStartDateTime= GETDATE()- @VarExpiredDays
SET @VarENDDateTime=GETDATE();
/*
select @VarStartDateTime
select @VarENDDateTime
*/
SELECT * FROM
(SELECT CONVERT(Varchar(11),@VarStartDateTime,106) AS VarStartDateTime) A,
(SELECT CONVERT(Varchar(11),@VarENDDateTime,106) AS VarENDDateTime) B
Verify the Execute SQL Task runs as expected. At this point, it simply becomes a matter of wiring up the outputs to SSIS variables. As you can see in the results window below, I created two package level variables StartDateText and EndDateText of type String with default values of an empty string. You can see in the Locals window they have values assigned that correspond to @VarExpiredDays = 10
in the supplied source query
Getting there is simply a matter of configuring the Result Set tab of the Execute SQL Task. The hardest part of this is ensuring you have a correct mapping between source system type and SSIS type. With an OLE DB connection, the Result Name has no bearing on what the column is called in the query. It is simply a matter of referencing columns by their ordinal position (0 based counting).
Final thought, I find it better to keep things in their base type, like a datetime data type and let the interface format it into a pretty, localized value.
c#
? – Darin Dimitrov