We help IT Professionals succeed at work.
Get Started

sql - update statement with variable parameters - how?

Last Modified: 2021-04-21
I've got my insert statement working recursively, but I don't know how to write the update statement to work in the same way. The way it is now just complains about being invalid.

Can anyone help re-write the statement so it works the same way as the insert above it, using string variables?

its an access database fyi
  dim MM_editCmd2, Connstring, Sql
  dim strcustomer_id, strtitle, strbookID, strsales_amnt

Set MM_editCmd2 = Server.CreateObject("ADODB.Connection")

' assign variables to items in the forms collection.
  'database connection
  'MM_editCmd2.provider = provider
  MM_editCmd2.ConnectionString = MM_conn_STRING
While (NOT WA_eCart_EOF(bookshop))
'Sql statement to insert the data
 strcustomer_id = identityValue
  strtitle = cStr(WA_eCart_DisplayInfo(bookshop, "Name"))
  strbook_ID = cStr(WA_eCart_DisplayInfo(bookshop, "ID"))
  strsales_amnt = cStr(WA_eCart_DisplayInfo(bookshop, "Price"))
  Sql="INSERT INTO Sales (customer_id, title, bookID, sales_amnt) VALUES ('" _
  			& strcustomer_id & "','" & strtitle & "','" _ 
				& strbook_ID & "','" & strsales_amnt & "')"
' execute it
set bookshop = WA_eCart_MoveNext(bookshop)
set bookshop = WA_eCart_MoveFirst(bookshop)

<%'update stock 
Dim MM_updateStock, strquantity, Sql2
Set MM_updateStock = Server.CreateObject ("ADODB.Connection")
MM_updateStock.ConnectionString = MM_conn_STRING
While (NOT WA_eCart_EOF(bookshop))
Sql statement to insert the data
strquantity = cStr(WA_eCart_DisplayInfo(bookshop, "quantity"))
strbookID = cStr(WA_eCart_DisplayInfo(bookshop, "ID"))
Sql2="UPDATE Stock set quantity = (quantity - 1) WHERE EXISTS (SELECT bookID FROM Sales WHERE Sales.bookID = Stock.bookID) VALUES ('" _& strquantity & "','" & strbookID & "')"
execute it
set bookshop = WA_eCart_MoveNext(bookshop)
set bookshop = WA_eCart_MoveFirst(bookshop)

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 12 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE