If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Sybase > ADT Upate SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-19-11, 14:59
MIKEWB20012000 MIKEWB20012000 is offline
Registered User
 
Join Date: Jan 2008
Posts: 24
ADT Upate SQL

Guys

I am completely new to this SQL - so bear with me!

At the moment I have a set of 30 files that simply updates two fields, but the where criteria is slightly different (ie., in the example below the cdocode changes).

I have tried to create one SQL that I can run that will update effectively using the or statement, example below:


UPDATE cdofile
SET status = ‘C’, statusnote = ‘autoclosure’
WHERE status = ‘N’ and cdocode=’10’ and email is null
Or status =’N’ and cdocode=’15’ and email is null

The issue is that I have 30 "or" lines and when the query is validated, I get "success", but when I run the query, it just never finishes and updates, it seems to hang without completing.

Does anyone have any suggestions on using the "or" or infact, the script itself?

Thanks in advance for any help !
Reply With Quote
  #2 (permalink)  
Old 04-20-11, 03:30
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
Operators have the following precedence from highest to lowest:

unary (single argument) – + ~
* / %
binary (two argument) + – & | ^
not
and
or

Operators at the same level execute left to right
You can change the order of execution with parentheses

So your where clause is the same as
WHERE (status = ‘N’ and cdocode=’10’ and email is null
and cdocode=’15’ and email is null) Or status =’N’

I think you want
WHERE status = ‘N’
and email is null
and cdocode in ('10','15')

What indexes exists?
Reply With Quote
  #3 (permalink)  
Old 04-20-11, 03:41
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
Operators have the following precedence from highest to lowest:

unary (single argument) – + ~
* / %
binary (two argument) + – & | ^
not
and
or

Operators at the same level execute left to right
You can change the order of execution with parentheses

So your where clause is the same as
WHERE (status = ‘N’ and cdocode=’10’ and email is null
and cdocode=’15’ and email is null) Or status =’N’

I think you want
WHERE status = ‘N’
and email is null
and cdocode in ('10','15')

What indexes exists?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On