Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

convert rows to columns in sql server

-- convert rows to columns in sql server (PIVOT)
SELECT Firstname, Amount, PostalCode
FROM (
         SELECT value, columnname
         FROM yourtable
     ) d
PIVOT (
    max(value)
    FOR columnname IN (Firstname, Amount, PostalCode)
) piv;
 
PREVIOUS NEXT
Tagged: #convert #rows #columns #sql #server
ADD COMMENT
Topic
Name
3+9 =