Friday, March 30, 2012

Multiple joins in a filter

I'm using Sql 2005 and merge replication.

I want to create a dynamic merge filter on a table but the data I filter on is only reachable by a few extra joins. For example:

I want to filter Table3. Table3 is joined to Table2 which in joined to Table1. Table1 contains the host_name column that I use to filter i.e. host_name = HOSTNAME().

In order to get filtered data in Table3 do I have to also filter Table 2 and Table1, or in my filter clause for Table3 can I say something like: Table3.FKid = Table2.Id and Table2.FKId = Table1.Id and Table1.host_name = HOSTNAME()?

I'm pretty sure I can't use AND in my dynamic filter clause but I just wanted to make sure.

Thanks for your help

Graham

The recommended way would be:

1. On T1: myFilterColumn=HOST_NAME()

2. On T2: add a join filter with sp_addmergefilter - T2.c1=T1.c1

3. On T3: add a join filter with sp_addmergefilter - T3.c3=T2.c2

No comments:

Post a Comment