xp_logininfo Return Value

  • Can someone point out what I’m doing wrong in trying to get a return value from the xp_logininfo.

    My Code is as follows:

    ALTER procedure Prog_Logins

    (@Account as Varchar (50))

    as

    Declare @jobstep varchar(128)

    Set Nocount ON

    Create Table #LoginsRead (

    [accountname] varchar(55),

    type varchar(25),

    privilege varchar (25),

    [mappedloginname] varchar (66),

    [permissionpath] varchar(66))

    select @jobstep = 'Domain\DB Read'

    insert into # LoginsRead ([accountname],type,privilege,[mappedloginname],[permissionpath])

    EXEC master..xp_logininfo @acctname = @account,@option = 'members'

    Declare @Read int

    Set @Read=(Select Count(AccountName) from #LoginsRead Where accountname=@Account)

    Print @Read

    --------------------------------------------------------------------------

    Create Table #LoginsWrite (

    [accountname] varchar(55),

    type varchar(25),

    privilege varchar (25),

    [mappedloginname] varchar (66),

    [permissionpath] varchar(66))

    select @jobstep = 'Domain\DB Write'

    insert into #LoginsWrite([accountname],type,privilege,[mappedloginname],[permissionpath])

    EXEC master..xp_logininfo @acctname = @account,@option = 'members'

    Declare @write int

    Set @write =(Select Count(AccountName) from #LoginsWrite Where accountname= @account)

    Select write =@write + 1

    Print @write

    ---------------------------------------------------------------------------

    Create Table #Admin (

    [accountname] varchar(55),

    type varchar(25),

    privilege varchar (25),

    [mappedloginname] varchar (66),

    [permissionpath] varchar(66))

    select @jobstep = 'BuiltIn\Administrators'

    insert into #Admin ([accountname],type,privilege,[mappedloginname],[permissionpath])

    EXEC master..xp_logininfo @acctname = 'BuiltIn\Administrators',@option = 'members'

    Declare @admin-2 int

    Set @admin-2=(Select Count(AccountName) from #Admin Where accountname=@Account)

    Select Admin = @admin-2 + 2

    Print @admin-2

    Declare @ReturnValue int

    --Count the ints

    -- 0 = no access

    -- 1 = read only

    -- 2 = full access

    -->4 = Admin

    Select @ReturnValue= @Read + @write + @admin-2

    Return @ReturnValue

    Print @ReturnValue

    Drop table #LoginsRead

    Drop table #LoginsWrite

    Drop table #Admin

  • Well, what are you expecting to get back?  For starters, it appears that you have a typo in your @write tally in the line: Select write =@write + 1.  Shouldn't this be Select @write =@write + 1 (you left the at sign off your write variable)?

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Well, what are you expecting to get back?  For starters, it appears that you have a typo in your @write tally in the line: Select write =@write + 1.  Shouldn't this be Select @write =@write + 1 (you left the at sign off your write variable)?

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Well, what are you expecting to get back?  For starters, it appears that you have a typo in your @write tally in the line: Select write =@write + 1.  Shouldn't this be Select @write =@write + 1 (you left the at sign off your write variable)?

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Well, what are you expecting to get back?  For starters, it appears that you have a typo in your @write tally in the line: Select write =@write + 1.  Shouldn't this be Select @write =@write + 1 (you left the at sign off your write variable)?

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Wow, sorry about the multi-post.  My PC blinked on me and it posted multiple times as I was still typing. 

    Anyhow, if my above suggestion does not help, please post a more detailed description of why it is not working as you would like and maybe some examples on what you are expecting. 

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Thanks for the feedback. I did forget to put the "@" before my variable. I also found out that I could not pass back the return variable during a calculation. I had to use:

    Set @login = @ENGRead + @write + @admin-2

    Select @ReturnValue =@Login

    Return @ReturnValue

    I'm using this to pull users from a AD group in SQL, then adding up the integers for specific rights they are supposed to have.

    Thanks

    CY

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply