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 > Adabas > SQL statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-26-04, 11:38
Tony McCluney Tony McCluney is offline
Registered User
 
Join Date: Feb 2004
Location: Southeast
Posts: 2
SQL statement

strsql = "UPDATE Shipping SET Shipping.Qty = Qty - 1 " _
& "WHERE (((Shipping.Qty)>0) " _
& "AND ((Shipping.PartNo)= '" & Forms![Axle]![Axle No] & "'"
& "))" _
& ""

dbs.Execute strsql

The above is VB code in an Access2000 application. I need it to update the first record that matches the criteria and no others. It currently updates each record in the Shipping table that matches the Axle No from the form.
Reply With Quote
  #2 (permalink)  
Old 02-27-04, 08:47
Cinil Cinil is offline
Registered User
 
Join Date: Feb 2004
Location: New Jersey
Posts: 17
Update statement

Hi
Your current statement is "Update tblname set cond1='cond1'
Change it to "Update tblname set cond1=(select top1 from tblname where cond1='cond1)".
Let me know if this works.Good luck.
Cinil
Reply With Quote
  #3 (permalink)  
Old 02-27-04, 10:45
Tony McCluney Tony McCluney is offline
Registered User
 
Join Date: Feb 2004
Location: Southeast
Posts: 2
Re: Update statement

Quote:
Originally posted by Cinil
Hi
Your current statement is "Update tblname set cond1='cond1'
Change it to "Update tblname set cond1=(select top1 from tblname where cond1='cond1)".
Let me know if this works.Good luck.
Cinil
Cinil,
Thank you for your response. I am still having trouble with the syntax of the SQL statement. I am not very familiar with SQL code and reqire a bit more explicit direction.
Tony
Reply With Quote
  #4 (permalink)  
Old 02-27-04, 11:26
Cinil Cinil is offline
Registered User
 
Join Date: Feb 2004
Location: New Jersey
Posts: 17
Re: SQL statement

Hi Tony,
I regret my first reply bcos it doesnt hold true always.The answer to your question is NO unless you change your WHERE clause.Else it will update all the rows.Try to find out some unique ids which you can include in your WHERE clause.The other way,but little more complicated, is to use cursors and exit from the loop after the first row.Having fun with sql...?
Cinil


Quote:
Originally posted by Tony McCluney
strsql = "UPDATE Shipping SET Shipping.Qty = Qty - 1 " _
& "WHERE (((Shipping.Qty)>0) " _
& "AND ((Shipping.PartNo)= '" & Forms![Axle]![Axle No] & "'"
& "))" _
& ""

dbs.Execute strsql

The above is VB code in an Access2000 application. I need it to update the first record that matches the criteria and no others. It currently updates each record in the Shipping table that matches the Axle No from the form.
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