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 6602435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:52:36+00:00 2026-05-25T18:52:36+00:00

I am writing a query that will be used in a .NET application, therefore

  • 0

I am writing a query that will be used in a .NET application, therefore I would like the SQL Server 2008 o do much of the processing for me instead of the client PC that the application will run on.

I am trying to get data from a single table with an index value, based off of that index value I would like that item to placed in a specific column.

Here is an example:

table MAS:

MA      SN      Mindex
B275    7A1515  1
B276    7A1515  2
E530    7A1515  3
B291    7A1519  1
B292    7A1519  2
E535    7A1519  3
B301    7A2515  1
B302    7A2515  2
B331    7A2519  1
B332    7A2519  2

Here is the output I would like:

 SN      mi1     mi2     mi3
 7A1515  B275    B276    E530
 7A1519  B291    B292    E535
 7A2515  B301    B302    null
 7A2519  B331    B332    null

I tried doing the following query, it works with items with 3 indexes but if there are only two, it fills it with random data.

 select mas1.SN, mas1.MA as mi1,mas2.MA as mi2, mas3.MA as mi3
 from MAS ma1, MAS ma2, MAS ma3
 where mas1.SN = '7A1515' and mas1.Mindex = '1' and mas2.Mindex = '2' and mas3.Mindex = '3'

I was wondering if anyone would be able to point me in the right direction as I am still fairly new at writing these advanced queries.

  • 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-25T18:52:37+00:00Added an answer on May 25, 2026 at 6:52 pm

    As you are on SQL Server 2008 you can also use PIVOT but the old style way of doing it is often easier IMO.

    SELECT 
        SN,
        MAX(CASE WHEN Mindex=1 THEN MA END) AS mi1,
        MAX(CASE WHEN Mindex=2 THEN MA END) AS mi2,
        MAX(CASE WHEN Mindex=3 THEN MA END) AS mi3
    FROM MAS
    GROUP BY SN     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a username, how would I go about writing an LDAP query that will
I need help writing a T-SQL query that will generate 52 rows of data
I am using SQL Server 2008. I am writing a query where I need
How would one go about writing a query that selects items 2000-2010 out of
I'm writing a query for an application that needs to list all the products
I'm writing a PHP script that builds an SQL query by concatenating the string
I know several ways of writing paged query in SQL Server 2005. But I
I am writing a simple data warehouse that will allow me to query the
I am in need of a scalable and performant HTTP application/server that will be
I'm writing a program using jdbc that will be an interface to database(smth like

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.