Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 953305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:01:57+00:00 2026-05-16T00:01:57+00:00

I have a table containing user-account permissions and I’m trying to write a query

  • 0

I have a table containing user-account permissions and I’m trying to write a query to return one row for each user-account combination.

Here is what I have.

CltKey  AcctKey TranTypeID  Access
10      2499    10          0
10      2499    11          1
10      2499    12          1
10      2764    10          1
10      2764    11          1
10      2764    12          0

Here is what I’d like to have.

CltKey  AcctKey TranTypeID1 Access1 TranTypeID2 Access2 TranTypeID3 Access3
10      2499    10          0       11        1       12        1
10      2764    10          1       11        1       12        0

Or even better something like this.

CltKey  AcctKey HasTranTypeID1  HasTranTypeID2 HasTranTypeID3
10      2499    0               1              1
10      2764    1               1              0    

I have tried doing a self join, but I keep getting multiple rows for each TranTypeID. One with it equal to 0 and another with it equal to 1. I have also tried using nested “Select” statements, but the performance is horrible. Does anyone have an idea on how to do this?

Thanks.

Edit: Unfortunately, this has to work in SQL 2000.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T00:01:57+00:00Added an answer on May 16, 2026 at 12:01 am

    It’s been a while since I used SQLServer 2000, but this will probably work.

    select cltkey, acctkey, 
    max( case when trantypeid = 10 and access = 1 
          then 1 else 0 end ) as hastrantypeid1,
    max( case when trantypeid = 11 and access = 1 
          then 1 else 0 end ) as hastrantypeid2,
    max( case when trantypeid = 12 and access = 1 
          then 1 else 0 end ) as hastrantypeid3
    from table
    group by cltkey, acctkey;
    

    If not, try this:

    create view has_access as 
    select cltkey, acctkey, 
    max( case when trantypeid = 10 and access = 1 
          then 1 else 0 end ) as hastrantypeid1,
    max( case when trantypeid = 11 and access = 1 
          then 1 else 0 end ) as hastrantypeid2,
    max( case when trantypeid = 12 and access = 1 
          then 1 else 0 end ) as hastrantypeid3
    from table;
    

    and then get your results from this

    select cltkey, acctkey, 
    max( hastrantypeid1) as hastrantypeid1,
    max( hastrantypeid2 ) as hastrantypeid2,
    max( hastrantypeid2 ) as hastrantypeid2
    from has_access
    group by cltkey, acctkey;
    

    Note that this will tell you a (cltkey, acctkey) has access (of a particular type) if any row for that tuple of (cltkey, acctkey) has access for that particular type. That is, it’s essentially a row-wise OR.

    If all rows for that tuple must have access for that tuple to have access, that is, if you want a row-wise AND, you’ll need to do this:

    min( case when trantypeid = 10 
          then case when access = 1 
                then 1 else 0 end else null end) as hastrantypeid1,
    etc.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one table containing user sessions and another to indicate violations in the
I have a table which have a row containing user emails and I want
Lets say that I have a table containing users . Each row in that
I have a table containing in every row one cell inside which is checkbox
I have a log table containing user ids, ip addresses and log in datetimes.
I have a table containing user sessions, i.e. a period a user is logged
I have a MySQL table containing user submitted data. I want the administrator to
I have a MySQL table containing userID , score . A single user can
I have a table containing users... one way or another some users were doubled
User has many Relationships In my relationships table i have a field :referee containing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.