users and roles listed separately from one query.

  • Hi Folks

    I have this query for user and roles from sysuers and sysmember table.. i want user name will be in separate column and roles in separate coulmn means two columns by running same query..

    Please help....

     

    SELECT     a.name

    FROM         db_2_3.dbo.sysusers a INNER JOIN

                          db_2_3.dbo.sysmembers b ON a.uid <> b.memberuid

    WHERE     (a.name NOT LIKE 'db%') AND (a.name NOT IN ('guest', 'public'))

     

    Thanx in advance

     

    SqlIndia

  • This was removed by the editor as SPAM

  • take your pick

    SELECT     a.name, '' as role

    FROM         dbo.sysusers a INNER JOIN

                          dbo.sysmembers b ON a.uid <> b.memberuid

    WHERE     (a.name NOT LIKE 'sa%') AND (a.name NOT IN ('guest', 'public'))

    union

    SELECT     '' as name, a.name as role

    FROM         dbo.sysusers a INNER JOIN

                          dbo.sysmembers b ON a.uid <> b.memberuid

    WHERE     (a.name NOT LIKE 'sa%') AND (a.name NOT IN ('guest', 'public'))

    --or

    SELECT     a.name, (

    SELECT     a1.name

    FROM         dbo.sysusers a1 INNER JOIN

                          dbo.sysmembers b1 ON a1.uid <> b1.memberuid

    WHERE     a.name = a1.name AND (a1.name NOT LIKE 'sa%') AND (a1.name NOT IN ('guest', 'public'))

    ) as role

    FROM         dbo.sysusers a INNER JOIN

                          dbo.sysmembers b ON a.uid <> b.memberuid

    WHERE     (a.name NOT LIKE 'sa%') AND (a.name NOT IN ('guest', 'public'))

    hope this helps

     

Viewing 3 posts - 1 through 2 (of 2 total)

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