i am trying to make a select statement on a datatable to get the row that is within the date range i am looking for. I am new to this an i dont quite understand how this sel
Using this inside an SSIS script component. I just used the example from above that included "#" around the dates. Also I converted each to string. This worked perfectly.
Just in case you want to know how I setup this up inside SSIS: First had a data flow using the recordset destination with an Object variable to store the recordset.
in my script I included the variable as a read only.
In the main class...
public class ScriptMain : UserComponent
{
OleDbDataAdapter a = new OleDbDataAdapter();
System.Data.DataTable AwardedVacTable = new System.Data.DataTable();
...
...
then in Pre-Execute...
public override void PreExecute()
{
base.PreExecute();
a.Fill(AwardedVacTable, Variables.rsAwardedVac);
...
...
then in a custom method accessed the datatable ...
String dtFilter = "EmployeeID = " + empId.ToString() + " AND (#" + Convert.ToString(StartDate) "# <= EndDate AND #" + Convert.ToString(StartDate) + "# >= StartDate" + " OR #" + Convert.ToString(StartDate.AddDays((double)numDays)) + "# >= StartDate AND #" + Convert.ToString(StartDate.AddDays((double)numDays)) + "# <= EndDate)";
DataRow[] Overlaps = AwardedVacTable.Select(dtFilter);
I posted an answer on this post.
DataTable Select by exact DateTime
You can use a similar approach by using ticks to select in a range.
Besides wrapping your dates with #, if date1 is a DateTime and not a string, you need to use the ToString(your date format) to get the correct sql statement. For debugging it make it easier if first you create a string containing your filter, then do the select using that string. Then you can look at the string and use that in the query builder to validate your sql.
expression = "Date > #2015-1-1#"; DataRow[] foundRows = table.Select(expression); 与 select * from tablename where Date>'2015-1-1'
This the Best Optimal Search Criteria I have Tested. you having to dates.
From_Date = 12/01/2012 To_Date = 12/31/2012
and Your column in DataTable upon which you applying . (in my code 'date')
Your Select Statement will be like this.
DataRow[] rows = newTable.Select("date >= #" + from_date + "# AND date <= #" + to_date + "#");