473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Script / Function ... to find difference b/w 2 similar tables

Hi,

I m searching for some Script / Function ... to find difference in data
b/w 2 similar tables (exactly same fields structure) in sql 2000.
plz update me asap !

thanks in advance !

Jul 23 '05 #1
2 1591
On 11 Jan 2005 22:34:27 -0800, AzGhanv/. wrote:
I m searching for some Script / Function ... to find difference in data
b/w 2 similar tables (exactly same fields structure) in sql 2000.
plz update me asap !


Hi AzGhanv/.,

SELECT CASE
WHEN a.KeyCol = 1 THEN 'FirstTable'
ELSE 'SecondTable'
END AS Origin,
COALESCE (a.KeyCol1, b.KeyCol1) AS KeyCol1,
COALESCE (a.KeyCol2, b.KeyCol2) AS KeyCol2,
.....
COALESCE (a.KeyColN, b.KeyColN) AS KeyColN,
COALESCE (a.DataCol1, b.DataCol1) AS DataCol1,
COALESCE (a.DataCol2, b.DataCol2) AS DataCol2,
.....
COALESCE (a.DataColN, b.DataColN) AS DataColN
FROM FirstTable AS a
FULL OUTER JOIN SecondTable AS b
ON a.KeyCol1 = b.KeyCol1
AND a.KeyCol2 = b.KeyCol2
.....
AND a.KeyColN = b.KeyColN
AND a.DataCol1 = b.DataCol1
AND a.DataCol2 = b.DataCol2
.....
AND a.DataColN = b.DataColN

NOTE: The above assumes that no column may contain NULLS. For each data
column that allow NULLS, you'll have to replace

AND a.DataColX = b.DataColX

with

AND (a.DataColX = b.DataColX
OR (a.DataColX IS NULL AND b.DataColX IS NULL))

or, alternatively

AND NULLIF (a.DataColX, b.DataColX) IS NULL
AND NULLIF (b.DataColX, a.DataColX) IS NULL

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #2
Assuming by differences you mean rows in A not in B as well as vice
versa, a good solution would be
create table t1 (a int,b int)
create table t2 (a int,b int)

insert into t1 values (1,2)
insert into t1 values(3,4)
insert into t1 values(5,6)
insert into t2 values(1,2)
insert into t2 values(3,7)
insert into t2 values(5,6)
select sum(t) ,a,b from

(select 1 as t,* from t1
union all
select 2 as t,* from t2
) as both
group by a,b
this way you see both kinds of differences as 1 or 2, and 3 means no
difference (you can add having sum(t)<3 not to see them)
hope this helps
Tzvika

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Henk Verhoeven | last post by:
(Reply on this newsgroup to an email - reply by email did not work) Wolfman wrote: > > Hi, > I found your Email in the php Newsgroup. > I was looking for some way to resize some graphiks on my...
1
by: David | last post by:
Hi everyone. I have read every page that Google returns on this topic, but can't find anything that resolves my problem. Basically, I have an Access Database that does a number of different...
7
by: Dr. Know | last post by:
I am working on an ASP page that writes to several databases, ranging from MDBs to x-base. One of the tasks involves using an existing highest value from the DB and incrementing it before...
15
by: greenflame | last post by:
First of all I only have IE for testing. Ok. I have a script that is supposed to show, not evaluate, the indefinite integral of something. When I run the script it just craches IE. I have tried...
3
by: Robi | last post by:
Ok, I'm sure everybody who works with javascript has seen this or similar messages depending on their agent: A script on this page is causing mozilla to run slowly. If it continues to run, your...
64
by: Morgan Cheng | last post by:
Hi All, I was taught that argument valuse is not supposed to be changed in function body. Say, below code is not good. void foo1(int x) { x ++; printf("x+1 = %d\n", x); } It should be...
20
by: none | last post by:
I have managed to get the below script *almost* working. However, it still has a problem calculating the number of months. The date I am trying to calculate from is Oct 15, 1994. With the correct...
17
by: CES | last post by:
All, I was wondering if their is a way of loading an external script fill from within a script?? <script language="javascript" type="text/javascript"> function test(var){ <script...
4
by: lisabelle | last post by:
Really, all I've ever done is a little html, but since FrontPage, hardly any. Now I am ready to sell my products after being online for a decade. I am newly signed up with Link Partners, and I get an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.