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
 Weird Issue with AND

Author  Topic 

SQLNOVICE999
Yak Posting Veteran

62 Posts

Posted - 2012-01-24 : 12:25:26

Hi Guys,

wanted to check if someone has seen this type of issue... and what was the reason behind it...

My colleague was running SQL with couple of AND
Ex:
SELECT * FROM PROJECT
WHERE PID = '3850' --CHAR(10)
AND INDID = 8565 --DECIMAL(10, 0)
AND NAME LIKE 'Contract%' --CHAR(100)

Somehow AND did not work correctly... when I ran the query in my computer it was fine.... This was very random.. She even showed me and when I changed the Order of PID and INDID in her computer it ran fine...

Not sure what might be the issue here as we want to make sure there is no issue in the DB..

Please let me know if you know anything on this..

Thanks,
Laura

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2012-01-24 : 12:30:54
What do you mean by:
quote:

omehow AND did not work correctly... when I ran the query in my computer it was fine.... This was very random.. She even showed me and when I changed the Order of PID and INDID in her computer it ran fine...

Did you maybe get a timeout?
Is that the *exact* code that was run?
is the code in a stored proc?

it could be that the the execution plan was recompiled by changing the order around by the logical condition is exactly the same.

AND is not broken. Something else is going on.

More information please?

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

SQLNOVICE999
Yak Posting Veteran

62 Posts

Posted - 2012-01-24 : 12:45:21
Sorry...

SELECT * FROM PROJECT
WHERE PID = '3850' --CHAR(10)
AND INDID = 8565 --DECIMAL(10, 0)
AND NAME LIKE 'Contract%' --CHAR(100)


The query above should have pulled Name starting with Contract for those PID and INDID, but it pulled all the records with those PID and INDID... I changed the order of PID and INDID the select worked fine; however, same issue was there for DELETE and UPDATE query... it is so incosistent... I thought the query was wrong first, but it did not seem like it...
quote:
Originally posted by Transact Charlie

What do you mean by:
quote:

omehow AND did not work correctly... when I ran the query in my computer it was fine.... This was very random.. She even showed me and when I changed the Order of PID and INDID in her computer it ran fine...

Did you maybe get a timeout?
Is that the *exact* code that was run?
is the code in a stored proc?

it could be that the the execution plan was recompiled by changing the order around by the logical condition is exactly the same.

AND is not broken. Something else is going on.

More information please?

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION


Go to Top of Page

SQLNOVICE999
Yak Posting Veteran

62 Posts

Posted - 2012-01-24 : 12:48:06
The query was executed in Query Analyzer... We opened new window and still had this issue in DELETE and Update while Select was pulling correct result...
Go to Top of Page

SQLNOVICE999
Yak Posting Veteran

62 Posts

Posted - 2012-01-24 : 13:21:12
We tried using Transaction using her computer and Even Rollback did not work... while it worked fine while I did it in my computer..

quote:
Originally posted by SQLNOVICE999

The query was executed in Query Analyzer... We opened new window and still had this issue in DELETE and Update while Select was pulling correct result...

Go to Top of Page
   

- Advertisement -