dorinda
asked on
UPDATE SQL Statement
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.BankRoutingNumbe r = Em". The whole SQL statement looks like this:
strSqlDocLstSeq = "Update Documents, Employees SET SeqNum = " & CheckNumber & _
" where Documents.BankRoutingNumbe r = Employees.UserRoutingNbr and" & _
" Documents.BankBranchNumber = Employees.UserBranch and Employees.UserLogin = '" & gbl_User_Login & "'" & _
" and Documents.DocType = '" & mstrCashCheck & "'"
db.Execute strSqlDocLstSeq
strSqlDocLstSeq = "Update Documents, Employees SET SeqNum = " & CheckNumber & _
" where Documents.BankRoutingNumbe
" Documents.BankBranchNumber
" and Documents.DocType = '" & mstrCashCheck & "'"
db.Execute strSqlDocLstSeq
nothing looks out of the ordinary with your syntax. Double-check your column names.
"... SET Documents.SeqNum = CheckNumer ..."
OR
"... SET Employees.SeqNum = CheckNumer ..."
OR
"... SET Employees.SeqNum = CheckNumer ..."
" where Documents.BankRoutingNumbe r = Employees.UserRoutingNbr and" &
Maybe a space after the "and" could help?
Maybe a space after the "and" could help?
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.
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.
or try this:
strSqlDocLstSeq = "Update Documents Inner Join Employees On (Documents.BankRoutingNumb er = 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.BankRoutingNumb er = 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
strSqlDocLstSeq = "Update Documents Inner Join Employees On (Documents.BankRoutingNumb
" and Documents.DocType = '" & Replace$(mstrCashCheck,"'"
or
strSqlDocLstSeq = "Update Documents Inner Join Employees On (Documents.BankRoutingNumb
" and Documents.DocType = '" & Replace$(mstrCashCheck,"'"
depending the SeqNum's source table.
Hope this help
You cannot update two tables in the same SQL query
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
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
ASKER
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.
ASKER
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.BankRoutingNumbe r = ' " & 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.
strSqlDocLstSeq = "Update Documents SET Documents.LastSeqNum = '" & CheckNumber & "'" & _
" where Documents.BankRoutingNumbe
" Documents.BankBranchNumber
" 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.
points? VCGuru stated the simple fact that led you to your solution, did he not?
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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!
Thanks you guys are wonderful!