I need to insert data by selecting some part of the values needed base on the supplied values from the user.
In a scenerio, the client will provide staff_name, customer_name, and product_name. The INSERT will look up the necessary data from other tables to pull the corresponding ids.
This is what I currently have
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)
but it does not insert any record
Thanks for your help
Actually, you have two separate queries here, which can be tested separately.
I mean, why don’t you test this part first:
And see if there are any data returned.