Avatar of Philippe Renaud
Philippe Renaud
Flag for Canada asked on

SQL Query problem

Hello EE,

I have a query results like this:

Name       Level      Key      Description          Jannuary    February
 
Peter          3            P           Peter's Sales        500               200
Isabel         3            P           Isa's Sales            200               450


How could I do a new query the results be like this :

Key              Peter Jan   Peter Feb         Isa Jan    Isa Feb
 
 P                    500               200                200        450

(since both lines on first query was P)   there is only 1 row on second query result and Vendors are horizontal. If there were 5 months they would have 5 months each...

is it possible ? ... thanks sql experts !!
Microsoft SQL ServerMicrosoft SQL Server 2005SQL

Avatar of undefined
Last Comment
SANDY_SK

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
SANDY_SK

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Philippe Renaud

ASKER
Ok but is there a way to to this without hardcoding the names ?
because tomorrow it could have 4 name (peter isa john mike) and the query wouldnt work anymore.. ?
SANDY_SK

Well if that is the case what you could do is use a stored procedure to construct the query in the same way. but then there will involve too many self joins, not too sure if that's a very efficient way.

There is one option of pivot tables but i don't thing it can be used in this scenario.

Exploring it, if i am able to get it will post it .
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck