Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 28th, 2007, 03:20 AM
Authorized User
 
Join Date: Oct 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Comparing values in records of same schema

Hi,
I have a problem in comparing a set of records of same schema.
Actually I have a set of records in a table having same ID n I have to find the variance between the fields.


Please reply me if U have some idea in this matter..





Thanks and Regards,
Jhansi
__________________
Thanks and Regards,
Jhansi
 
Old December 28th, 2007, 06:15 AM
Friend of Wrox
 
Join Date: Oct 2007
Posts: 130
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via AIM to urtrivedi
Default

You should always post your table structure and required output.
Anyway if you want to query one table more than once, then you can do it in following manner.
Consider following table EMPLOYEE, col MNGRID is self referencing col EMPID

PK->EMPID
COL->EMPNAME
FK->MNGRID


SELECT A.EMPID,A.EMPNAME,A.MNGRID,B.EMPNAME MANGERNAME
FROM EMPLOYEE A
INNER JOIN EMPLOYEE B ON (A.MNGRID=B.EMPID)



urt
 
Old December 28th, 2007, 07:33 AM
Authorized User
 
Join Date: Oct 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

lets a table having fields..EmpID,City,PhoneNumber
this table contains a set of records for the same EmpID(EmpID is not a primary key here) with different city and PhoneNumber.In this case I have to identify the variance in each record.

for example the following is the recordset
EmpID City PhoneNumber ID
==== ====== ============ ===
123 Blore 080123456 1
123 Chennai 044123467 2
123 Blore 080123445 3

Now I need the variance in each record..
the output should come like this...

fieldName UpdatedFrom UpdatedTo
========= =========== =========
City Blore Chennai
PhoneNumber 080123456 044123467
City Chennai Blore
PhoneNumber 044123467 080123445


If U have some idea please do send asap.

Thanks and Regards,
Jhansi
 
Old December 28th, 2007, 08:48 AM
Friend of Wrox
 
Join Date: Oct 2007
Posts: 130
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via AIM to urtrivedi
Default

I am Assuming that your for empid 123 there are id's with 1,2, 3. same way if empid 150 has

5 records then their ids are expected to numbered as 1,2,3,4,5.

Following query works on above assumption other wise you have to use cursor and scan each

row one by one.

SELECT A.EMPID,A.CITY AS ORGCITY, B.CITY AS NEWCITY,A.PHONENUMBER AS ORGPHONENUMBER,
B.PHONUMBER AS NEWPHONENUMBER
FROM EMPTABLE A
INNER JOIN EMPTABLE B ON A.EMPID=B.EMPID AND A.ID+1=B.ID
WHERE A.CITY<>B.CITY OR A.PHONENUMBER<>B.PHONENUMBER

IF INFORMATIOIN IS CHANGED,
EMPID WITH MAXID WILL NOT COME AND UNCHANGED ROW WILL NOT COME
 OUTPUT WILL BE FOLLOWING
EMPID ORGCITY NEWCITY ORGPHONENUMBER NEWPHONENUMBER
123 BLORE CHENNAI 080123456 044123467
123 CHENNAI BLORE 044123467 080123445

urt





Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing Two values from same table MArgente BOOK: Beginning SQL 3 December 11th, 2009 07:35 AM
Comparing values between different MSHFlexGrid davekrunal46 Visual Basic 2005 Basics 0 November 28th, 2005 07:42 AM
Comparing values between different MSHFlexGrid davekrunal46 VB How-To 0 November 28th, 2005 07:41 AM
Comparing values between different MSHFlexGrid davekrunal46 VB Databases Basics 0 November 28th, 2005 07:39 AM
Comparing values between different MSHFlexGrid davekrunal46 Beginning VB 6 0 November 28th, 2005 07:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.