我需要根据用户提供的值选择所需的部分值来插入数据。
在一个场景中,客户将提供staff_name, customer_name
和product_name
。INSERT
将从其他表中查找必要的数据以提取相应的 id 。
这是我目前拥有的
INSERT INTO [Order](product_id,
customer_id,
staff_id,
vehicle_regno,
order_details,
total_price,
order_date)
SELECT
stock.id,
customers.id AS Expr1,
Staff.id AS Expr2,
@vehicle_regno AS Expr3,
@order_details AS Expr4,
@total_price AS Expr5,
@order_date AS Expr6
FROM
stock
CROSS JOIN
customers CROSS
JOIN
Staff
WHERE
(stock.name = @stock_name)
AND (customers.name = @customers_name)
AND (Staff.name = @staff_name)
但它不插入任何记录
谢谢你的帮助