The parameterization available in SSIS is dependent upon the connection manager used.
OLE DB and ODBC based connection managers use ?
as the variable place holder, whereas ADO.NET uses a named parameter, @myVariable
.
OLE DB begins counting at 0 whereas ODBC used a 1 based counting system. They are both however ordinal based systems so in your CASE expression the two ?
are for the same variable. But, you'll have to list that SSIS Variable twice in the parameter mapping dialog because it's ordinal based - i.e. (param, name) => @HoursBack, 0; @MyVar, 1; and @MyVar, 2;
A "dumb trick" I would employ if I had to deal with repeated ordinal based parameters or if I was troubleshooting packages is to make the supplied query use local variables in the query itself.
DECLARE
@HoursBack int = ?
, @MyVariable int = ?;
SELECT
TimeSeriesIdentifier
, StationID
, ParameterID
FROM
dbo.EtlView
WHERE
LastModified > DATEADD(HOUR, @HoursBack * -1, GETDATE())
AND StationID LIKE
CASE
WHEN @MyVariable = 0 THEN StationID
ELSE @MyVariable
END;
Now I only have to map the SSIS Variable @MyVar once into my script as the "normal" TSQL parameterization takes over. The other benefit is that I can copy and paste that into a query tool and sub in the ?s with actual values to inspect the results directly from the source. This can be helpful if you're running into situations where the strong typing in SSIS prevents you from getting the results into a data viewer.