I put together a sample scenario of my issue and I hope its enough for someone to point me in the right direction.
I have two tables
Products
Product Meta
I need a result set of the following
I put together a sample scenario of my issue and I hope its enough for someone to point me in the right direction.
I have two tables
Products
Product Meta
I need a result set of the following
use the stored procedure here: http://www.sqlteam.com/article/dynamic-cross-tabs-pivot-tables
also check the comments.
If your database engine is 2005 and your database is in 2000 compatibility mode, you can work around the lower compatibility mode by running your query from a 2005 database. Target the 2000 database by using 3 part naming convention for your tables in the query such as
DatabaseNameHere.dbo.TableNameHere
I realize this is two years old, but it bugs me that the accepted answer calls for using dynamic SQL and the most upvoted answer won't work:
You must use a Group By or you will get a staggered result. If you are using a Group By, you must wrap each column that is not in the Group By clause in an aggregate function (or a subquery).
We've successfully used the following approach in the past...
It can also be useful transposing aggregations with the use of...
EDIT
Also worth noting this is using ANSI standard SQL and so it will work across platforms :)