April 10, 2023 at 1:02 pm
I'm trying to use the if then else to check if a member exist in a server role. if it does, do X, else do Y. but not getting the desire outcome.
BEGIN
DECLARE @member nvarchar(50);
USE [master]
SELECT@member = members.name
FROM sys.server_role_members AS server_role_members
INNER JOIN sys.server_principals AS roles
ON server_role_members.role_principal_id = roles.principal_id
INNER JOIN sys.server_principals AS members
ON server_role_members.member_principal_id = members.principal_id
WHERE roles.name = 'TEST_Role'
and members.name = 'Joe Blow'
Select @member;
IF @member = 'Joe Blow'
begin
PRINT 'Great! ';
END
ELSE
BEGIN
PRINT 'not great';
END
END
April 10, 2023 at 1:28 pm
i'm able to figure out. not sure how to delete this post
April 10, 2023 at 3:23 pm
you don't delete it - just put your solution here for others to see in case they have the same issue.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply