• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

Sql query syntax

Hello i have this query :

SET @query = N'SELECT Parent_Key_Desc, '+
            @cols +'
            (SELECT  t1.Parent_Key_Desc, t1.CompanyNo, t1.[tya]
            FROM   table1  AS t1) p
            FOR companyNo IN
            ( '+
            @cols +' )
            ) AS pvt
            order by Parent_Key_Desc;'

this works well.
but lets say I had one more column to pivot ? not only  MAX([tya]) but also lets say MAX([tyb])

looks like the pivot doens like I put 2 columns inside parentheses... how do we do this ?
1 Solution
Nico BontenbalCommented:
I think you need to create 2 pivots. 1 for tya and 1 for tyb and then join the results.
For one way, Nicobo's idea is correct, try it. Waiting for your comment if you need more help.
PhilippeRenaudAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now