Here is what is in SSIS script task in visual c#
public void Main()
{
// TODO: Add your code here
int Var_Flag = (int)Dts.Variables["Var_Flag"].Value; // 1 for manual run, 0 for incremental since last run
DateTime Start_Date = (DateTime)Dts.Variables["Var_StartDate"].Value; // Start DateTime of the previous run. Start at this date if run is set to manual
DateTime End_Date = (DateTime)Dts.Variables["Var_EndDate"].Value; // End DateTime of the previous run. End at this date if run is set to manual
String SQL = "";
// If incremental run, our current run needs to start at the end date from the previous run and include everything up to today's date
// Format the SQL string
SQL = "SELECT * " + " from rz_ibsv.dbo.INTGR_INSTLD_BASE_SRVC_CNTRCT_F"+
// "WHERE " +
//"(convert(datetime2,UPD_GMT_TS) >=CONVERT(DATETIME,'" + Start_Date + "',131) AND convert(datetime2,UPD_GMT_TS) < CONVERT(DATETIME,'" + End_Date + "',131)) ";
//"(convert(UPD_GMT_TS >=cast('" + Start_Date + "',datetime) AND UPD_GMT_TS < cast('" + End_Date + "',datetime) ";
//"UPD_GMT_TS BETWEEN '" + Start_Date + "' and '" + End_Date + "'";
"(UPD_GMT_TS >=CONVERT(datetime,'" + Start_Date.ToString() + "') AND UPD_GMT_TS < CONVERT(datetime,'" + End_Date.ToString() + "')) ";
// Return the SQL string to the global variable
Dts.Variables["Intervention_Parts_Qry"].Value = SQL;
Dts.TaskResult = (int)ScriptResults.Success;
}
What this code does is .
- It takes 2 datetime values fills it in 2 variable .
- then these 2 variables are used to create sql statement which selects data between the 2 variable range .
- This sql statment is used in execute sql task to select desired output .
I am getting error as :
[OLEDB_SRC- COREIB CONTRACT DATA [1]] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. 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: "Incorrect syntax near '>'.".
Need help resolving this issue :)