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 2005 Forums
 Transact-SQL (2005)
 table always provided different results when run..

Author  Topic 

dnf999
Constraint Violating Yak Guru

253 Posts

Posted - 2009-12-07 : 11:36:00
I have a query which is driving me nuts at the moment. Basically the tables TEMP_FILTER_4_DEBITS_SUM and TEMP_FILTER_4_CREDITS_SUM always remain static, yet when I run the following query, the result set can change everytime I re-create the above tables.

SELECT A.*, B.TOTAL_CREDITS, B.TOTAL_TRANS_CREDITS
INTO TEMP_FILTER_4_SUM_MATCHES
FROM TEMP_FILTER_4_DEBITS_SUM A
INNER JOIN TEMP_FILTER_4_CREDITS_SUM B
ON A.DATE = B.DATE
AND A.DESCRIPTION = B.DESCRIPTION
AND A.LEDGER = B.LEDGER
AND A.TOTAL_DEBITS = B.TOTAL_CREDITS

I am not sure why this is doing this...!

I know I have been a bit vague(and you can't see the data), but I was just wondering if there's anything that stands out to explain why the results would change everytime I ran the above query.....

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-12-07 : 11:47:22
are totaldebits and totalcredits the same datatype?

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

dnf999
Constraint Violating Yak Guru

253 Posts

Posted - 2009-12-07 : 12:03:02
Yes.

What I think it might be is that the Date, Description, Ledger and Debits/Credits does not always identify a unique record...

But why would it change everytime...?
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-12-07 : 12:25:40
In what way is the dataset different? Are the data different, the order they're displayed in? Also, how are you creating the tables each time? If you don't specyify data types, sql will make a decision on what the datatype should be and it might be wrong.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -