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
 General SQL Server Forums
 New to SQL Server Programming
 query rearranges in sql server

Author  Topic 

angelaHLP
Starting Member

2 Posts

Posted - 2011-01-28 : 13:58:43
Hi all,

I'm not really new to SQL Server, but I have this issue every one in awhile for some time.

I've created a query, but when I run it in SQL Server 2003 Enterprise Manager it rearranges it into a query that is not what I want. If anyone can explain this to me I would be eternally grateful.

This is the query I start with:
SELECT *
FROM Orders O
INNER JOIN ShoppingCarts SC
ON SC.shoppingcartid = O.fk_shoppingcartid
WHERE O.cartname = 1 AND( O.name IS NULL OR (O.type IS NULL AND O.option LIKE 'No%') )

When run it converts the query to:
SELECT *
FROM Orders O INNER JOIN
ShoppingCarts SC ON SC.shoppingcartid = O.fk_shoppingcartid
WHERE (O.name IS NULL) AND (O.cartname = 1)
OR (O.type IS NULL) AND (O.option LIKE 'No%')
AND (O.carname = 1)

This is obviously not what I want. Thanks for any response!

Angela

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-01-28 : 14:04:32
So how about running it in Query Analyzer instead where you won't see a query get converted at all? Using Enterprise Manager to run and write queries is not a good thing.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

angelaHLP
Starting Member

2 Posts

Posted - 2011-01-28 : 14:41:02
tkizer,

Thanks for the quick reply. The thing is that I'm running the query in ColdFusion and it is rearranging it when running there the same as in SQL Enterprise Manager. So that is why I was using it in the example.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-01-28 : 15:11:10
call a stored procedure?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -