Solved

UPDATE SQL Statement

Posted on 2002-07-14
13
278 Views
Last Modified: 2010-05-02
I am new to SQL and am trying to execute the following statement but my program keeps giving me an error invalid syntax at the "where Documents.BankRoutingNumber = Em".  The whole SQL statement looks like this:

strSqlDocLstSeq = "Update Documents, Employees SET SeqNum = " & CheckNumber & _
" where Documents.BankRoutingNumber = Employees.UserRoutingNbr and" & _
" Documents.BankBranchNumber = Employees.UserBranch and Employees.UserLogin = '" & gbl_User_Login & "'" & _
" and Documents.DocType = '" & mstrCashCheck & "'"

db.Execute strSqlDocLstSeq

0
Comment
Question by:dorinda
13 Comments
 
LVL 45

Expert Comment

by:aikimark
ID: 7153339
nothing looks out of the ordinary with your syntax.  Double-check your column names.
0
 
LVL 4

Expert Comment

by:TigerZhao
ID: 7153355
"... SET Documents.SeqNum = CheckNumer ..."
OR
"... SET Employees.SeqNum = CheckNumer ..."
0
 
LVL 4

Expert Comment

by:Monchanger
ID: 7153395
" where Documents.BankRoutingNumber = Employees.UserRoutingNbr and" &

Maybe a space after the "and" could help?
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 39

Expert Comment

by:appari
ID: 7153430
which database are you using?
in oracle and SQL Server "Update Documents, Employees .... " this wont work.

in SQL Server you can try
 Update Documents set ...
from  Employees
or
 Update Employees set ...
from  Documents

once check update statements syntax.

hope this helps you.

0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 7153588
or try this:

strSqlDocLstSeq = "Update Documents Inner Join Employees On (Documents.BankRoutingNumber = Employees.UserRoutingNbr and Documents.BankBranchNumber = Employees.UserBranch) SET Document.SeqNum = " & CheckNumber & " Where Employees.UserLogin = '" & Replace$(gbl_User_Login,"'","''") & "'" & _
" and Documents.DocType = '" & Replace$(mstrCashCheck,"'","''") & "'"

or

strSqlDocLstSeq = "Update Documents Inner Join Employees On (Documents.BankRoutingNumber = Employees.UserRoutingNbr and Documents.BankBranchNumber = Employees.UserBranch) SET Employees.SeqNum = " & CheckNumber & " Where Employees.UserLogin = '" & Replace$(gbl_User_Login,"'","''") & "'" & _
" and Documents.DocType = '" & Replace$(mstrCashCheck,"'","''") & "'"

depending the SeqNum's source table.

Hope this help
0
 
LVL 3

Expert Comment

by:VCGuru
ID: 7153594
You cannot update two tables in the same SQL query
0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7153629
I dont know if one can update 2 tables this way directly.

I think, you can use a "Trigger" or call a "Stored Procedure" passing the table names or new values as parameters and in that stored procedures, maybe you can update the 2 tables with the values you passed as parameters.

Hope this info helps!

-priya
0
 

Author Comment

by:dorinda
ID: 7154520
Thanks all for your suggestions!!. But, I am still fighting with it.  I am using MySQL.  Maybe this information will help give someone an idea.  I am trying to update the documents.LastSeqNum field in the documents table only.  I just need the branch and routing number of the employee so I know which document record to update.  
0
 

Author Comment

by:dorinda
ID: 7154615
Well, I have gotten around the problem and created global variables for the fields in the employee table.  Here is what I am using.

strSqlDocLstSeq = "Update Documents SET Documents.LastSeqNum = '" & CheckNumber & "'" & _
" where Documents.BankRoutingNumber = ' " & gbl_Bank_Rout_Number & "'" & "and " & _
" Documents.BankBranchNumber = '" & gbl_Branch_Number & "'" & _
" and Documents.DocType = '" & mstrCashCheck & "'"

So, what do I do about the points?? If someone can give me any other pointers on the Update statement when I need information from two tables I would be happy to give them the points.  Thanks.
               
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 7154663
points? VCGuru stated the simple fact that led you to your solution, did he not?
0
 

Author Comment

by:dorinda
ID: 7177506
Not really because I just needed information from the second table I NEVER wanted to change information in the second table...I was really doing more of a join on the routing numbers to find the proper record to update in the ONE table.
0
 
LVL 45

Accepted Solution

by:
aikimark earned 100 total points
ID: 7177654
For MySQL, you might use:

strSqlDocLstSeq = "Update Documents  SET SeqNum = " & CheckNumber & _
" where Documents.BankRoutingNumber = (Select Employees.UserRoutingNbr From Employees Where " & _
" Documents.BankBranchNumber = Employees.UserBranch and Employees.UserLogin = '" & gbl_User_Login & "') " & _
" and Documents.DocType = '" & mstrCashCheck & "'"

db.Execute strSqlDocLstSeq

======================================
This assumes that CheckNumber is a column in the Documents table.
0
 

Author Comment

by:dorinda
ID: 7178232
That is what I needed...I did modify the first line for the Update statement to what I was using but from the where  forward is what I was looking for...

Thanks you guys are wonderful!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
add text to end of existing text in file 16 70
Updates not working for MS Windows 7 12 164
How to debug this code 7 61
Getting warning: You are about to delete 1 row(s) 9 48
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

815 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now