-1
Я пытаюсь получить количество из таблицы пунктов заказа и цены из таблицы продуктов, а затем умножить их на @OrderTotal, и функция вернет общую сумму заказа. Я студент и был болен, когда лектор объяснил это, пожалуйста, помогите :)Я пытаюсь сделать заказ всего t-sql
Код:
create function [worksheet02].[udf_getOrderTotal](@orderID Bigint)
returns Bigint
as
begin
declare @OrderTotal Bigint
declare @quantity integer
declare @price integer
@quantity = (select quantity
from [worksheet02].[tbl_order_items]
where order_id = @orderID);
@price = (select unit_price
from [worksheet02].tbl_order_items oitm
join[worksheet02].[tbl_products] prd
on(oitm.product_id =prd.product_id)
where oitm.order_id = @orderID);
@OrderTotal = @quantity * @price;
return @orderTotal;
end;
go
Ошибка:
Msg 102, Level 15, State 1, Procedure udf_getOrderTotal, Line 68
Incorrect syntax near '@quantity'.
Msg 102, Level 15, State 1, Procedure udf_getOrderTotal, Line 72
Incorrect syntax near '@price'.
Msg 102, Level 15, State 1, Procedure udf_getOrderTotal, Line 78
Incorrect syntax near '@OrderTotal'.
'SET @quantity = ...', 'SET @price = ...', 'SET @OrderTotal = ...' – squillman