Options

Filter rows before data compare

RippoRippo Posts: 10
edited August 17, 2005 12:54PM in SQL Toolkit Previous Versions
Hi

I need to be able to filter rows before I perform a DATA compare using the SQL toolkit.

I have read a post where an example called selectionDelegate was emailed to the user.

http://www.red-gate.com/MessageBoard/viewtopic.php?t=658&highlight=filter

Please can you send me this example or point me to a url where I can see this working?

Thanks
Richard Wilde

Comments

  • Options
    Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hello Richard,

    I've posted some (reasonably complex) selectiondelegate code to the Knowledge Base.

    You may need to be aware, though, that the SelectionDelegate merely acts as a filter to the rows of data that will be synchroinized. It does not actually stop the data from being compared in the first place. All of the data must be compared first.

    Here is a link to the code:

    http://www.red-gate.com/messageboard/vi ... php?t=1067
  • Options
    Thanks for that. I have run an example and this seems to work ok.

    One more thing would really help me is that I need to only perform this on certain tables

    Please can you aid me in intregrating this into your example?

    I have the code to this

    foreach (TableDifference difference in obComparisonSession.TableDifferences)
    {
    if (difference.Name.ToLower() == "[dbo].[links]")
    {
    difference.Selected = true;
    }
    else
    {
    difference.Selected = false;
    }
    }
    Does this go before

    RedGate.SQL.Shared.ExecutionBlock obExeBlock = obSqlProvider1.GetMigrationSQL(obComparisonSession, IncludeRowDelegate, false);

    Also I need to perform the comparison on an unkown quantity of record ID's within a single table. Can you offer some advice on how I would do this.

    I look forward to your reply.

    Many thanks
    Richard
  • Options
    Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hello Richard,

    In the example, this is the bit that chooses which tables will be selected for comparison:
    foreach (RedGate.SQLDataCompare.Engine.Table Table in obCompareTables) 
    			{
    				if (Table.Fields["CompanyID"]!=null) obTableComparisonSettings.Add(obTCS = new SQLDataCompare.Engine.TableComparisonSetting(Table.FullyQualifiedName, Table.Fields, Table.PrimaryKey.Fields));
    			}
    
    I would imagine that you should change this a bit:
    foreach (RedGate.SQLDataCompare.Engine.Table Table in obCompareTables) 
    			{
    				if (Table.FullyQualifiedName.ToLower()=="[dbo].[links]") obTableComparisonSettings.Add(obTCS = new SQLDataCompare.Engine.TableComparisonSetting(Table.FullyQualifiedName, Table.Fields, Table.PrimaryKey.Fields));
    			}
    
This discussion has been closed.