Solved

update query Error Result

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

Containers and Docker for Everyone

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 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