Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Compare records in table

Author  Topic 

vmon
Yak Posting Veteran

63 Posts

Posted - 2004-09-03 : 13:37:47
I need to compare records ordered in a table to identify when certain fields change values. I need to compare record 1 with 2, and 2 with 3, and 3 with 4. Checking 5 different fields for changes between the records. Is there a simple way to get this done in tsql?

Thanks in advance,
vmon

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-03 : 13:50:32
will this be of any help?


SELECT *
FROM MyTable
WHERE col1 IN (col2, col3, ..., col(n))
OR col2 IN (col3, ..., col(n))
OR col3 IN (..., col(n))
...
OR col(n-1) in (col(n))




Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

vmon
Yak Posting Veteran

63 Posts

Posted - 2004-09-03 : 14:01:17
Not sure I follow how I could use your idea. Maybe this will help.

REC1, M1, P123, HPM101, 9000, 104
REC2, M1, P123, HPM101, 9000, 104
REC3, M1, P403, HPM101, 9000, 100
REC4, M1, P500, HPM101, 8000, 111

I need to be able to create a record by selecting out record 2 and 3 to indicate change in col3 between records. I also need to create another record by selecting out 3 and 4 to indicate change between records in col3, col5 and col6. Can I join the tables together and compare records or something?

vmon
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-03 : 14:58:20
maybe this will help:
http://www.sqlteam.com/item.asp?ItemID=12654



Go with the flow & have fun! Else fight the flow :)
Go to Top of Page
   

- Advertisement -