1

目前我有将记录插入到 tbl_order 的更新代码。现在我实现了库存部分。我需要系统可以在订单完成后从库存中减去数量。

我正在考虑 INSERT (Subtract (od_qty-tbl_inventory.inv_qty)) 但我不知道在这种情况下 SQL 语句将如何。所以请你帮忙。谢谢

下面是我当前将数据插入到 tbl_order 的更新代码。

<% 
dim od_total, cal_total, od_qty
cust_id = request.querystring("cust_id")
bill_id = request.querystring("bill_id")
pd_id = request.querystring("pd_id")
od_price = request.querystring("od_price")
od_qty = request.querystring("od_qty")
od_qty_unit = request.querystring("od_qty_unit")

date_current = date

        od_total = od_price * od_qty


Dim conn ' ADO connection
Dim rstSimple ' ADO recordset
Dim strDBPath ' path to our Access database (*.mdb) file
Dim bill_total

set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("../database/tkp.mdb"))
set rs=Server.CreateObject("ADODB.recordset")

' Next, the script inserts the form inputs retrieved from the querystring into the database table:
sql="INSERT INTO tbl_order (cust_id,bill_id,pd_id,od_price,od_qty,od_qty_unit,od_total)"
sql=sql & " VALUES "
sql=sql & "(" & cust_id & ","
sql=sql & "'" & bill_id & "',"
sql=sql & "'" & pd_id & "',"
sql=sql & "" & od_price & ","
sql=sql & "" & od_qty & ","
sql=sql & "'" & od_qty_unit & "',"
sql=sql & "" & od_total & ")"


'response.write sql
on error resume next
conn.Execute sql
if err<>0 then
Response.Write("No update permissions!") 'ae_name field is primary key so new record not inserted if name pre-exists in table
else
'Response.Write("<h3> Record added</h3>")
end if

rstSimple.Close
Set rstSimple = Nothing

conn.Close
Set conn = Nothing
%>
4

2 回答 2

2

您需要对库存表运行更新查询,从当前库存量中减去订单数量。像这样的东西:

sql = "UPDATE tbl_inventory SET inv_qty = inv_qty - " & od_qty & " WHERE pd_id = " & pd_id
于 2012-10-02T03:49:29.083 回答
1

您将能够解决您的事务处理问题

conn.BeginTrans
'—Run Your Statements Here
conn.Execute sql1
conn.Execute sql2
conn.CommitTrans

请参阅此了解更多信息:http ://classical-asp.blogspot.com/2010/08/transaction.html

编辑:确保 inv_date 列是日期时间列

sql1 = "UPDATE tbl_inventory SET inv_qty_act = inv_qty_act - " & od_qty & ", inv_date = now() WHERE pd_id = '" & pd_id & "'"
于 2012-10-01T10:56:24.847 回答