March 16, 2009 at 5:04 pm
i have a database table tab1.
There are two views v1 and v2 written by some user.
We dont know how they are written.
When i execute v1 and v2 we are getting some values.
Is there any simple way to check if both the views are giving same values(after sorting the results)
March 16, 2009 at 5:06 pm
Do these views return any unique id?
Greets
Flo
March 16, 2009 at 5:23 pm
yah. they both return same data type (lets consider it as varchar datatype)
March 16, 2009 at 5:29 pm
In this case its simple. Use a FULL join and exclude the matches by WHERE id columns are NULL:
DECLARE @v1 TABLE (id INT, txt VARCHAR(100))
DECLARE @v2 TABLE (id INT, txt VARCHAR(100))
INSERT INTO @v1 VALUES (1, 'aaa')
INSERT INTO @v1 VALUES (2, 'bbb')
INSERT INTO @v2 VALUES (2, 'bbb')
INSERT INTO @v2 VALUES (3, 'ccc')
SELECT *
FROM @v1 v1
FULL OUTER JOIN @v2 v2 ON v1.id = v2.id
WHERE v1.id IS NULL OR v2.id IS NULL
Greets
Flo
March 16, 2009 at 6:06 pm
Thanks for your reply. i verified it was working gr8.
but i dont think its working for comparing data with duplicate values.
like the below.
DECLARE @v1 TABLE (id INT, txt VARCHAR(100))
DECLARE @v2 TABLE (id INT, txt VARCHAR(100))
INSERT INTO @v1 VALUES (1, 'aaa')
INSERT INTO @v2 VALUES (1, 'aaa')
INSERT INTO @v2 VALUES ( 1, 'bbb')
SELECT *
FROM @v1 v1
FULL OUTER JOIN @v2 v2 ON v1.id = v2.id
WHERE v1.id IS NULL OR v2.id IS NULL
March 16, 2009 at 10:17 pm
harish_ravi (3/16/2009)
Thanks for your reply. i verified it was working gr8.but i dont think its working for comparing data with duplicate values.
like the below.
DECLARE @v1 TABLE (id INT, txt VARCHAR(100))
DECLARE @v2 TABLE (id INT, txt VARCHAR(100))
INSERT INTO @v1 VALUES (1, 'aaa')
INSERT INTO @v2 VALUES (1, 'aaa')
INSERT INTO @v2 VALUES ( 1, 'bbb')
SELECT *
FROM @v1 v1
FULL OUTER JOIN @v2 v2 ON v1.id = v2.id
WHERE v1.id IS NULL OR v2.id IS NULL
Then, just take out the WHERE clause.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply