?
Solved

update query Error Result

Posted on 2013-11-19
5
Medium Priority
?
225 Views
Last Modified: 2014-04-25
Hi All:
I've two table Cashier and proforma, I'd like to update field some fields in cashier according to the value of proforma. I've run the query everything is OK except On field  (Paid).
structurethe query i've wrote as following
        With DM.MyQuery4 Do
        Begin
                Close;
                SQL.Clear;
                SQL.Add('update cashier a inner join proforma b on ((b.tktno=a.docno) and (a.status=1)) set  a.paid=b.amount, a.invno= :x66, a.invstatus=:x22,a.dueamount=0, a.Cashierid=:x55 , a.receiptno= :x33, a.cashdate= :x44 ');
                ParamByName('x22').asinteger:=1;
                ParamByName('x55').asstring:=MF.GenUserSign;
                ParamByName('x33').asstring:=L1.Text;
                ParamByName('x44').AsDate := STRTODATE(FormatDateTime('dd/mm/yyyy',DTP1.DATE));
                ParamByName('x66').asinteger:=Strtoint(xgeninvno);
                Execute;
        End;

Open in new window


the result of the query is OK except the last record as shown in the following image
error result
0
Comment
Question by:khaled salem
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 1000 total points
ID: 39661285
I think you've got the wrong join criterion.

update cashier a inner join proforma b on ((b.docno=a.docno) and (a.status=1)) set  a.paid=b.amount, a.invno= :x66, a.invstatus=:x22,a.dueamount=0, a.Cashierid=:x55 , a.receiptno= :x33, a.cashdate= :x44 ');
               

In your example proforma has no tktno field.  I'm guessing that the real one has that field and it does not always equal docno.
0
 
LVL 25

Expert Comment

by:jogos
ID: 39661501
Previous comment could be the one.
In an update especialy when it is more complex with the join is not so easy to pinpoint errornas in a select.
As a general rule i write the update first as a select, including at least  the join and filter columns columns to check if the basics of the query are good.
0
 
LVL 32

Expert Comment

by:Daniel Wilson
ID: 39663211
As a general rule i write the update first as a select, including at least  the join and filter columns columns to check if the basics of the query are good
.

Yes, an excellent practice that has saved me much embarrassment!
0
 
LVL 35

Expert Comment

by:David Todd
ID: 39663473
Hi,

If you format it right, you can leave the select version of the query in but just commented out.

as in
update e
    set b = something
-- select b
from dbo.SomeTable e
where
    somewhereclause
;

so the select can be rerun for debugging purposes, but the update is what is executed in the procedure ...

HTH
  David
0
 

Author Comment

by:khaled salem
ID: 39671893
Hi:
 i am trying to select everything before update the query return perfect result. " This is strange case" by simple words there is two fields (paid, amount) , i would like to set paid = amount joining on b.docno= a.docno .  its seems so easy
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question