all groups > sql server replication > june 2005 >
You're in the

sql server replication

group:

Merge replication and dynamic filters question


Merge replication and dynamic filters question Zzzbla
6/14/2005 11:25:57 AM
sql server replication:
Hi!

I have a schema that looks like this, on my main server:

table Files:
FileID (PK)
FileName

table FileProperties
PropertyID
FileID (FK Files.FileID) (PK)
PropertyName (PK)
PropertyValue

table Hosts_Files
HostName (PK)
FileID (PK)

Now what I want to achieve is this:
There are many clients that use this database. Sometimes they go
offline and take some of the files with them to work offline.
When this occurs, I want to replicate the entire table Files, and only
the rows from FileProperties that have to do with the files they
downloaded to their computer (marked so in Hosts_Files).

Can I make this work with merge replication? I tried but the dynamic
filters I can write are either JOIN or WHERE (or am I wrong?) so I
couldn't manage to do a join between FileProperties and Hosts_Files
only where Hosts_Files.HostName = host_name().

Thanks in advance for answering,
Re: Merge replication and dynamic filters question Paul Ibison
6/14/2005 7:56:10 PM
You could join these tables in the merge publication. Filtering in this case
is a bit tricky as it looks as though you want to change the filter
effectively dynamically. I'm assuming that there is a typo somewhere, as
this doesn't seem to make logical sense: "I want to replicate the entire
table Files, and only the rows from FileProperties that have to do with the
files they downloaded to their computer" - this would seem to imply all
FileProperties. The way I read your requirements are that you want users to
select certain files and have just associated details downloaded? If this is
the case, you can have a further table which relates fileids to hostnames.
Selecting to download a file will cause an insert of a record in this new
table. All tables would be joined on fileid, and the dynamic filter would be
solely to the new table.
HTH,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)

Re: Merge replication and dynamic filters question Zzzbla
6/19/2005 1:50:25 AM
Hi Paul,

I forgot to mention that the rows in the files table correlate to
physical files. So what I wanted is to have some *physical* files
downloaded to the client's computer, all of the rows in the files table
(the client may have to see or use data about files that he didn't
download) and only the rows in the fileproperties table that are
related to the few rows in files table that are related to the physical
files the user downloaded.

I know I can join the tables - FileProperties and the table that
associates the fileid to the hostname - but when I also need to use
WHERE Hosts_Files.HostName = host_name(). I tried to do it but the
replication wizard doesn't let me.

If you could provide me with a script or an example solution (or is it
just a view that I have to write in order to combine JOIN and WHERE
filters?), I'll be grateful.

Thanks in advance,
Zzzbla

[quoted text, click to view]
Re: Merge replication and dynamic filters question Zzzbla
6/19/2005 4:00:33 AM
Some additions:

The real problem I'm facing is that the table I want to filter by
(Hosts_Files) is only related to the table I want to filter
(FileProperties) via the table Files - which I want to leave unfiltered.

If I let it filter the files table, I get the FileProperties I wanted,
but I also get only the selected rows from files and not the whole
table as required.


I wouldn't want to create a Hosts_FileProperties unless there's no
Re: Merge replication and dynamic filters question Paul Ibison
6/19/2005 12:30:53 PM
Please post up the schema of hte tables involved and I'll have a look. A
(denormalized) linking table will work (maintained by triggers) but there
might be an alternative.
HTH,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)

AddThis Social Bookmark Button