﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 7,2000 / T-SQL  / compare the value in a column against multiple databases / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 22 May 2013 06:51:06 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: compare the value in a column against multiple databases</title><link>http://www.sqlservercentral.com/Forums/Topic1422353-8-1.aspx</link><description>I haven't got SQL2000, but I think this will work.Assuming I've understood the problem, ie it's the comparison &amp; not the fact it's across databases...I've used 3 tables on the same DB, but it should work across databases.You could end up with 2 nulls if neither B or C match...[code="sql"]--== Sample Data ==--use tempdbgoif object_id('tempdb..#Customer1') is not null drop table #Customer1if object_id('tempdb..#Customer2') is not null drop table #Customer2if object_id('tempdb..#Customer3') is not null drop table #Customer3create table #Customer1(customer_name varchar(30),address varchar(30),city varchar(30))insert into #Customer1 values ('Joe James', '43 Holgate St', 'York')insert into #Customer1 values ('Ken Fletcher', '15 North St', 'Leeds')create table #Customer2(customer_name varchar(30),address varchar(30),city varchar(30))insert into #Customer2 values ('Joe James', 'Holgate St', 'York')insert into #Customer2 values ('Ken Fletcher', '15 North St', 'Leeds')create table #Customer3(customer_name varchar(30),address varchar(30),city varchar(30))insert into #Customer3 values ('Joe James', '43 Holgate St', 'York')insert into #Customer3 values ('Ken Fletcher', 'North St', 'Leeds')--== Example to show result from joins ==--Select 	A.customer_name, A.address, A.city, 	B.customer_name, B.address, b.city, 	c.customer_name, c.address, c.cityfrom #Customer1 as A	left join #Customer2 as B on left(A.customer_name,18) = left(B.customer_name,18) 		and A.Address = B.Address and A.City = B.City	left join #Customer3 as C on left(A.customer_name,18) = left(C.customer_name,18) 		and A.Address = C.Address and A.City = C.City--== Possible Solution ==--Select 	ISNULL(B.customer_name, C.customer_name) as customer_name,	ISNULL(B.address, C.address) as address,	ISNULL(B.city, C.city) as cityfrom #Customer1 as A	left join #Customer2 as B on left(A.customer_name,18) = left(B.customer_name,18) 		and A.Address = B.Address and A.City = B.City	left join #Customer3 as C on left(A.customer_name,18) = left(C.customer_name,18) 		and A.Address = C.Address and A.City = C.City[/code]</description><pubDate>Thu, 21 Feb 2013 08:04:45 GMT</pubDate><dc:creator>laurie-789651</dc:creator></item><item><title>compare the value in a column against multiple databases</title><link>http://www.sqlservercentral.com/Forums/Topic1422353-8-1.aspx</link><description>Using SQL 2000I have a table in Database A, lets call it customer.In the customer table there are several columns but I am interested in customer_name and address and cityI want to do a comparison against similar tables in other databases.Sample TSQLSelect A.customer_name, A.address, A.city, B.customer_name, B.address, b.city, c.customer_name, c.address, c.cityfrom customer as Ajoin DatabaseB.dbo.customer as B on left(A.customer_name,18) = left(B.customer_name,18) join DatabaseC.dbo.customer as C on left(A.customer_name,18) = left(B.customer_name,18) The above is for example only and may not be entirely correct.My challenge isI want to return to my result set one record for each possible match based on the best match.Meaning if Database B matches exactly on customer_name and address and city but Database C does not then only return database B's results.I don't know if this is possible but if anyone can show me how to get the results I need I would greatly appreciate it.</description><pubDate>Wed, 20 Feb 2013 16:39:28 GMT</pubDate><dc:creator>GF</dc:creator></item></channel></rss>