CREATE FUNCTION GetInStockIDByMaterialID(@materialID NVARCHAR(50))
RETURNS int
AS
BEGIN
DECLARE @userId int
IF @materialID IS NULL
RETURN NULL
SELECT @userId=B.UserID
FROM dbo.wh_WareHouseRefCategory AS A INNER JOIN dbo.wh_WareHouseRefUser AS B
ON A.WareHouseID=B.WareHouseID AND A.CategoryID=SUBSTRING(@materialID,1,8)
RETURN @userId
END
GO
原文:http://www.cnblogs.com/denghuachengle/p/3897529.html