rows to column sql

Shambhu Rai 1,411 Reputation points
2022-07-14T08:54:36.4+00:00

Hi Expert,

I wanted tp convert columns into rows using the conversation table. How i can do it

here is my source:

220751-image.png

Conversation table

220742-image.png

Expected output

220716-image.png

needs to convert this using case statement or any other method and column in rows in azure

Azure SQL Database
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,477 questions
SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,993 questions
SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,643 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,690 questions
{count} votes

Accepted answer
  1. Olaf Helper 46,041 Reputation points
    2022-07-14T09:34:50.257+00:00

    This should work:

    ;WITH cte AS  
        (SELECT 'Cycle' AS Property  
                Cycle AS Value  
         FROM SourceTable  
         UNION ALL  
         SELECT 'Car' AS Property  
                Car AS Value  
         FROM SourceTable)  
    SELECT *  
    FROM cte  
         INNER JOIN  
         ConversionTable AS T  
             ON cte.Value >= T.Min  
                AND cte.Value < T.Max  
      
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.