2 回答
TA贡献1829条经验 获得超13个赞
/*
获取两个数值的大小
0:小于;1:大于;2:等于
*/
CREATE function GetMax(@qty1 varchar(50),@qty2 varchar(50))
returns int
begin
declare @Num int
if (convert(decimal(18,5),@qty1)-convert(decimal(18,5),@qty2) >0)
begin
set @Num=1
end
else if (convert(decimal(18,5),@qty1)-convert(decimal(18,5),@qty2) <0)
begin
set @Num=0
end
else
begin
set @Num=2
end
return @Num
TA贡献1836条经验 获得超3个赞
打开SQL,然后按F1,然后搜索CREATE FUNCTION,说明很详细,自己看吧。
CREATE FUNCTION Sales.fn_SalesByStore (@storeid int)
RETURNS TABLE
AS
RETURN
(
SELECT P.ProductID, P.Name, SUM(SD.LineTotal) AS 'YTD Total'
FROM Production.Product AS P
JOIN Sales.SalesOrderDetail AS SD ON SD.ProductID = P.ProductID
JOIN Sales.SalesOrderHeader AS SH ON SH.SalesOrderID = SD.SalesOrderID
WHERE SH.CustomerID = @storeid
GROUP BY P.ProductID, P.Name
);
GO
- 2 回答
- 0 关注
- 968 浏览
添加回答
举报