Click here to Skip to main content
15,893,722 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey all!

I have a database I designed to track various products. Its rows look something like this:

ProductName | Year | Price | Margin | Cost of Good | Profit |

I am designing a grid. Currently, the view is as follows. ProductName is new and not currently taken into account.

------------------------------------------------------

Year 1 Year 2 Year 3 Year 4

Price

Margin

Cost of Good

Profit

-------------------------------------------------------

Let's say I have two products differentiated by ProductName. I would like to create a query which allows me to produce a grid that looks like this:

-----------------------------------------------------------

Year 1 Year 2 Year 3 Year 4

Price (Product 1)

Price (Product 2)

Margin (Product 1)

Margin (Product 2)

Cost of Good (Product 1)

Cost of Good (Product 2)

Profit (Product 1)

Profit (Product 2)

------------------------------------------------------


Can anyone help me with the SQL query to produce the data alternating like this by product?
Posted

1 solution

Sounds like you are trying to use a pivot table result.

see the following link
Simple Way To Use Pivot In SQL Query[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900