我花了一些代碼在這裏:Check if role consists of particular user in DB?檢查用戶屬於DB角色
SELECT *
FROM sys.database_role_members AS RM
JOIN sys.database_principals AS U
ON RM.member_principal_id = U.principal_id
JOIN sys.database_principals AS R
ON RM.role_principal_id = R.principal_id
WHERE U.name = 'operator1'
AND R.name = 'myrole1'
該查詢返回1行。這意味着用戶'operator1'屬於角色'myrole1'。 現在我試圖創建一個存儲過程是:
CREATE PROCEDURE [dbo].[Proc1]
(
@userName varchar,
@roleName varchar
)
AS
IF EXISTS(SELECT *
FROM sys.database_role_members AS RM
JOIN sys.database_principals AS U
ON RM.member_principal_id = U.principal_id
JOIN sys.database_principals AS R
ON RM.role_principal_id = R.principal_id
WHERE U.name = @userName
AND R.name = @roleName)
RETURN 0
ELSE RETURN -1
我使用標準的命令從SQL Server 2008「執行存儲過程」
DECLARE @return_value int
EXEC @return_value = [dbo].[Proc1]
@userName = N'operator1',
@roleName = N'myrole1'
SELECT 'Return Value' = @return_value
GO
它總是返回-1。 爲什麼 ???
感謝您的輸入,Templar。 對不起,長時間的答案。我不知道我應該把你的答案標記爲有用的和其他的東西...... – 2010-03-29 13:21:47