Solved

update query Error Result

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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 …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
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…

791 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