Solved

update query Error Result

Posted on 2013-11-19
5
211 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 500 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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