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

  • SEARCH
  • Home
  • 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 9143491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:02:22+00:00 2026-06-17T10:02:22+00:00

I could really use some help creating a pivot table. I have data in

  • 0

I could really use some help creating a pivot table. I have data in some rows that instead need to be appear in columns, juxtaposed next to values in other records.
The data is currently in the following format:

Region  |  Location  |  Customer | CustomerKey |Status
North   |  New York  |  John     | 111         |Active
North   |  New York  |  Mary     | 112         |Active
North   |  Delaware  |  Bob      | 113         |Idle
North   |  New Jersey|  Bob      | 113         |Active
West    |  California|  Bob      | 113         |Inactive
West    |  Washington|  Greg     | 114         |Inactive
West    |  Utah      |  Tim      | 115         |Active
North   | All States |  Bob      | 113         |VIP Customer
North   | All States |  Mary     | 112         |Regular Customer
West    | All States |  Bob      | 113         |Regular Customer
West    | All States |  Tim      | 115         |Regular Customer
West    | All States |  Greg     | 114         |VIP Customer
North   | All States |  John     | 111         |Regular Customer

The issue is with the ‘Status’ column, which can have one group of values (Inactive/Active/Idle) and another (VIP Customer and Regular Customer). When the ‘Location’ column is ‘All States’, it uses the VIP/Regular values. I would like to add a column, to have the data appear along the lines of:

Region  |  Location  |  Customer | CustomerKey |Status   | VIPStatus
North   |  New York  |  John     | 111         |Active   | No
North   |  New York  |  Mary     | 112         |Active   | No
North   |  Delaware  |  Bob      | 113         |Idle     | Yes
North   |  New Jersey|  Bob      | 113         |Active   | Yes
West    |  California|  Bob      | 113         |Inactive | No
West    |  Washington|  Greg     | 114         |Inactive | Yes
West    |  Utah      |  Tim      | 115         |Active   | No

Basically, if the Customer has a record with the Status of a ‘VIP Customer’, under a combination of a Region and a corresponding Location value of ‘All States’, then it will show a ‘VIPStatus’ of ‘Yes’ or ‘No’ under any record of that customer under that given Region (regardless of the Location state). Is there a simple solution for this? Any help on rearranging this data would in T-SQL would be greatly appreciated.

  • 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-06-17T10:02:23+00:00Added an answer on June 17, 2026 at 10:02 am

    You should be able to join on the table multiple times to get the result that you need:

    select t1.region,
      t1.location,
      t1.customer,
      t1.customerkey,
      t1.status,
      case when t2.status is not null then 'Yes' else 'No' end VIPStatus
    from yourtable t1
    left join yourtable t2
      on t1.CustomerKey = t2.CustomerKey 
      and t2.Location = 'All States' 
      and t2.status = 'VIP Customer'
    where t1.Location <> 'All States' 
    

    See SQL Fiddle with Demo

    The result is:

    | REGION |   LOCATION | CUSTOMER | CUSTOMERKEY |   STATUS | VIPSTATUS |
    -----------------------------------------------------------------------
    |  North |   New York |     John |         111 |   Active |        No |
    |  North |   New York |     Mary |         112 |   Active |        No |
    |  North |   Delaware |      Bob |         113 |     Idle |       Yes |
    |  North | New Jersey |      Bob |         113 |   Active |       Yes |
    |   West | California |      Bob |         113 | Inactive |       Yes |
    |   West | Washington |     Greg |         114 | Inactive |       Yes |
    |   West |       Utah |      Tim |         115 |   Active |        No |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I could really use some help. I have the following two lines. <TD noWrap>Data:
I could really use some help optimizing a table on my website that is
I could really use some help with files (images) download/save application process. I need
I could really use some help. I have a javascript / jquery slider below
I'm new to Python and could really use some help. I have a large
I have just started learning python/matplotlib/basemap and could really use some help. How do
I could really, really, really use some help. I have looked everywhere on some
I could really use some help with what I have a feeling will be
I could really use some help here. I just created a new bare repo
I am really new to Ruby and could use some help with a program.

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.