skip to Main Content

enter image description here

Hello everyone,

1/ I want to do a sql query that transform the result from row to column like it’s shown in the picture. Is it possible ?

2/ How can I update the second table with the first one ?

2

Answers


  1. You could use in the query

    select 'EH545WL' as name, EH545WL as value from car union select 'FJ281TJ' as name, FJ281TJ as value from car;
    

    If you use this query, you could get the result you want.
    Thank you

    Login or Signup to reply.
  2. There are several ways that you can transform this data.

    Create Table:

    CREATE TABLE yourTable([EH545WL] varchar(10), [FJ281TJ] varchar(10));
    
    INSERT INTO yourTable
    VALUES
        (0,0);
    

    Unpivot table:

    SELECT ID,Value
    FROM yourTable
    UNPIVOT (value for ID in ([EH545WL],[FJ281TJ])) up
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search