请问,这个储存过程看不懂
下面的例子来自MSDN:http://msdn.microsoft.com/zh-cn/library/ms188655
储存过程主体:
CREATE PROCEDURE Sales.uspGetEmployeeSalesYTD
@SalesPerson nvarchar(50),
@SalesYTD money OUTPUT
AS
SET NOCOUNT ON;
SELECT @SalesYTD = SalesYTD
FROM Sales.SalesPerson AS sp
JOIN HumanResources.vEmployee AS e ON e.BusinessEntityID = sp.BusinessEntityID
WHERE LastName = @SalesPerson;
RETURN
GO
调用储存过程:
DECLARE @SalesYTDBySalesPerson money;
EXECUTE Sales.uspGetEmployeeSalesYTD N'Blythe', @SalesYTD = @SalesYTDBySalesPerson OUTPUT;
PRINT 'Year-to-date sales for this employee is ' + convert(varchar(10),@SalesYTDBySalesPerson);
GO
问题:
@SalesYTD参数是OUTPUT型,意味着可以传入值、传出值,可是,在储存过程主体中,@SalesYTD在等号左边啊,怎么能传入值呢?
[解决办法]
@SalesYTD = @SalesYTDBySalesPerson OUTPUT
楼主是在疑问这句么?这里相当于获取存储过程传出参数的具体值,语法如此。
[解决办法]
@SalesYTD是output参数,不是input参数
[解决办法]
楼主也可以这么执行
DECLARE @SalesYTDBySalesPerson money;
EXECUTE Sales.uspGetEmployeeSalesYTD N'Blythe',@SalesYTDBySalesPerson OUTPUT;
也可以
EXECUTE Sales.uspGetEmployeeSalesYTD @SalesPerson
= N'Blythe',@SalesYTD = @SalesYTDBySalesPerson OUTPUT;
[解决办法]