Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query return different results in Query Analyzer

Status
Not open for further replies.

coolbeachguy

Programmer
Feb 1, 2006
3
0
0
US
Hi,

I executed this query:

SELECT * FROM Orders where LocationID = 21 ORDER BY OrderNumber DESC

It returns 22 records.

Then I executed this query:

SELECT * FROM Orders where LocationID = 21 AND OrderNumber = 8145 ORDER BY OrderNumber DESC

The second query returns record, but this record is not returned by the first query. And it should be.

Both queries are executed in Query Analyzer.

I tried to execute both queries from Enterprise Manager, and both return correct results. So only incorrect in the Query Analyzer.

Any input is appreciated.

Thanks,

coolbeachguy


 
<blind guessing>
SET ROWCOUNT in action?
</blind guessing>

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
<more blind guessing>
Could it be that QA and Enterprise Manager used different indexes to get the data, and one of the indexes has gone wacky. Try rebuilding the indexes and then re-runt he query.
</more blind guessing>

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Hm... I've never heard of something like

INDEXPROPERTY(tableID, index, 'GoNutsInQueryAnalyzer')

[smile]

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Not working guys. :)

I have never seen something like this either, it's weird

 
OK, simple test:

SELECT COUNT(*) FROM Orders where LocationID = 21
SELECT COUNT(*) FROM Orders where LocationID = 21 and OrderNumber = 8145
SELECT COUNT(*) FROM Orders where LocationID = 21 and OrderNumber <> 8145

Results are... ?

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Also run

SELECT * FROM Orders WHERE OrderNumber = 8145

How many LocationID 21's are there....
 
ok:

SELECT COUNT(*) FROM Orders where LocationID = 21

returns 885 records, on both QA and Enterprise Manager.

SELECT COUNT(*) FROM Orders where LocationID = 21 and OrderNumber = 8145

returns 3 records, on both QA and Enterprise Manager.

SELECT COUNT(*) FROM Orders where LocationID = 21 and OrderNumber <> 8145

returns 882 records, on both QA and Enterprise Manager.

SELECT * FROM Orders WHERE OrderNumber = 8145

return 3 records

So all of those queries return correct results.

The one that does not work is if I do the ORDER BY OrderNumber DESC, in QA it does not return the correct results, in Enterprise Manager it does.

However, this is odd: when I do the ORDER BY OrderNumber ASC, it return correct results in both QA and Enterprise Manager.





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top