Forum Discussion

Binarak's avatar
Binarak
Copper Contributor
Aug 26, 2022

Vertical results from multiple columns

Hello all,

I am very new to SQL and I don't have so much experience. I am trying to help with a report and I am trying to gather results from 3 columns and stack it vertically. This is the query I have. I simplified it a bit for demo.

 

 

Results

 

What I am trying to get an output of something like this...

Study IDB10Value
   
Study1B10-1123
Study1B10-2234
Study1B10-3345
Study2B25-1147

 

If you guys can give me a hand I'd really appreciate it. I've been thinking of "Union", "Pivot" but I am not sure to how to apply for this scenario.

Please help!

 

Thank you all!

    • Binarak's avatar
      Binarak
      Copper Contributor

      olafhelper 

      Hello good sir. Thank you so much for taking time to respond. I thought that the screenshot might be too small. I wasn't sure how to give a clear view. Ill give you a better picture. 

      Thank you so much.

      • Hi Binarak 

         

        First, welcome to the family of SQL Server users 

        Even if the image is big and we can read the content, it is still an image and not queries - text which we can copy->test->fix...

         

        What do you think will be simpler and faster. Option one: each one of the 100 people that come to the forum to help others instead of helping 10 people, will spend all his time to manually check the image -> type the query. Or maybe option two: one person who asked the question and has all the information will simply provide the query instead images?!?

         

        Please provide: 

        1) Queries to CREATE your table(s)
        2) Queries to INSERT sample data.
        3) The desired result given the sample.
        4) A short description of the business rules.
        5) Which version of SQL Server you are using.

Resources