Where clause with date type. Need help

Automate and integrate using the SQL comparison API

Moderator: Chris Auckland

Where clause with date type. Need help

Postby compvis » Thu Mar 31, 2011 9:56 am

hi,

I have a table with a field that has data type is date. So how can i filter data in table by date type, like:

Code: Select all
TableMappings mappings = new TableMappings();
sourcedb.Register(sourcecn, Options.Default);
targetdb.Register(targetcn, Options.Default);
mappings.CreateMappings(sourcedb.Tables, targetdb.Tables);

foreach(TableMapping tbm in mappings)
{
    if (tbm.Obj1.Name == "DQP_T3")
    {
           tbm.Include = true;
           tbm.Where = new RedGate.SQLDataCompare.Engine.WhereClause("Date >= 10/10/2000 && Date <= 10/10/2011");
     }
     else
     {
           tbm.Include = false;
     }
}

Thanks
compvis
 
Posts: 9
Joined: Mon Aug 02, 2010 7:43 am

Postby james.billings » Fri Apr 01, 2011 1:04 pm

That looks reasonable, except as it's a SQL clause, you need to use AND rather than && - for instance:

tbm.Where = new RedGate.SQLDataCompare.Engine.WhereClause("Date >= 10/10/2000 AND Date <= 10/10/2011");

Does that help? Also, to avoid any potential confusion over date formats you may want to specify the dates as yyyy-mm-dd.
james.billings
 
Posts: 1144
Joined: Wed Jun 16, 2010 11:10 am
Location: My desk.


Return to SQL Comparison SDK Previous Versions

Who is online

Users browsing this forum: No registered users and 0 guests