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
 SQL Server Development (2000)
 Hashing a query

Author  Topic 

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2007-07-09 : 09:12:24
Hi all,

I've got a problem where I want to compare the output of two select statements against each other for each employee in my database (a selection on the same set of data but orderd by different fields). I would like to hash the output of the select to some string or binary value so I can have a temp table in the following structure..

CREATE TABLE #ApprovalEventList (
employeeId BIGINT PRIMARY KEY,
initatedDateIdHASH ??,
standardIdHASH ??
)


I'd then be able to very quicky determine who my problem employees are (the 2 select statements with different ORDER BY clauses should return exactly the same order but they don't for at least 1 person I know of).

Any hints?

I'm running sql server 2000

-------------
Charlie

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-07-09 : 09:25:32
you can use union for this.

and how exactly do you expect to return the results in the same order if you specify different order by statements?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2007-07-09 : 09:29:39
The table I'm selecting against has a running identity and an initiatedDate field -- in all cases the order should be the same if I list (by employee) ordered by id or initatedDate (but somehow sadly, it is not).

How would I use UNION in this situation?

-------------
Charlie
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-07-09 : 09:56:51
assuming you want to have the same results returned from query 1 and query 2
if you do
query 1
union
query 2

if will remove duplicates. so if the count of query 1 (and thus query 2 since you want them to be same) is different
than the union-ed count the resultsets aren't same

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2007-07-09 : 11:32:04
Thanks for the info, nice and simple in the end.

Ta.

-------------
Charlie
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-07-09 : 11:58:09
it usually is

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page
   

- Advertisement -