2012-01-17 164 views

回答

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; 
+0

你不需要開始/結束。 – 2012-01-17 00:10:09

+0

使用returnvalue創建存儲函數會更好嗎?相反,返回resultSet會有什麼不同嗎? – 2012-01-17 00:20:50

+0

剛剛編輯我的帖子與功能。請檢查這個。 – 2012-01-17 00:25:25

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