Comparing Tuples in SQL

Posted by Brad on Stack Overflow See other posts from Stack Overflow or by Brad
Published on 2009-04-04T03:48:19Z Indexed on 2010/04/07 2:23 UTC
Read the original article Hit count: 456

Filed under:
|
|
|
|

Is there any more convenient way to compare a tuple of data in T-SQL than doing something like this:

SELECT TOP 100 A, B
FROM MyTable
WHERE (A > @A OR (A = @A AND B > @B))
ORDER BY A, B

Basically I'm looking for rows with (A, B) > (@A, @B) (the same ordering as I have in the order by clause). I have cases where I have 3 fields, but it just gets even uglier then.

© Stack Overflow or respective owner

Related posts about sql

Related posts about comparison