我有一个包含3列的表:username
,password
和permission
。我正在尝试编写一个存储过程来接受@username
作为输入参数,然后输出参数@permission
。我该怎么做?
答案 0 :(得分:9)
可能需要更多,但根据您的问题,这是代码:
CREATE PROCEDURE [dbo].[GetPermission]
@userName varchar(50),
@permission int output
AS
BEGIN
select @permission = PERMISSION from USERS where UserName = @userName
END;
编辑:
另一种选择是创建一个函数,例如:
CREATE FUNCTION [dbo].[GetPermission](@userName [varchar(50)])
RETURNS [int]
AS
BEGIN
declare @permission int
select @permission = PERMISSION from USERS where UserName = @userName
return @permission
END;
答案 1 :(得分:0)
只需添加到Gustavo F点,输出参数的ParameterDirection应设置为ParameterDirection.Output。
答案 2 :(得分:0)
CREATE PROC SP_ORDERS AS BEGIN SELECT DISTINCT E.EmployeeID,E.FirstName+SPACE(3)+E.LastName AS CUTNAME,E.City,ET.TerritoryDescription,P.ProductName, OD.Discount,SUM(OD.Quantity*OD.UnitPrice)AS TOTAL FROM [DimOrder Details] OD JOIN DimOrders O ON OD.OrderID=O.OrderID JOIN DimProducts P ON OD.ProductID=P.ProductID JOIN DimEmployees E ON O.EmployeeID=E.EmployeeID JOIN DimCustomers C ON O.CustomerID=C.CustomerID JOIN DimEmployeeTerritories ET ON E.EmployeeID=ET.EmployeeID GROUP BY E.EmployeeID,E.FirstName,E.LastName,E.City,ET.TerritoryDescription,P.ProductName,OD.Discount END