Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Translate rown in columns

Author  Topic 

tudorn
Starting Member

4 Posts

Posted - 2012-10-08 : 14:17:22

Hello,

I have the folowing TitleDetailsRequest table:

Title Store EN_No FR_No RequestDate
------ ------ ----- ----- -----------
Title1 StoreA 1 2 2012-07-12
Title1 StoreA 8 11 2012-10-05
Title1 StoreB 3 4 2012-10-01
Title2 StoreA 0 5 2012-09-28
Title2 StoreC 6 3 2012-07-15
Title4 StoreA 9 7 2012-08-10
Title4 StoreB 2 5 2012-09-04
Title4 StoreB 10 3 2012-10-03
Title4 StoreC 7 12 2012-08-20



I need to get an output of the EN_No and FR_No for all the Stores and for all the titles Title based on the latest RequestDate as follow:

Title1 Title2 Title3 Title4
------------- ------------- ------------- -------------
EN_No FR_No EN_No FR_No EN_No FR_No EN_No FR_No
------------- ------------- ------------- -------------
StoreA 8 11 0 5 0 0 9 7
StoreB 3 4 0 0 0 0 10 3
StoreC 0 0 0 0 0 0 7 12
------------- ------------- ------------- -------------
Totals 11 15 6 8 0 0 26 22

[img=left]C:\Documents and Settings\dorin.tudorica\My Documents\My Pictures\TitleDetailsRequest_Output.JPG[/img=left]

The Title table have all the titles that need to be in the output, so if a title is not in the TitleDetailsRequest table (i.e. Title3) the output should just display "0". Curently there are 30 titles in the Title table but the users can add new titles so hardcoding the titles into columns will not be an option considering that the users can also add new titles.

Your help with regards to this matter will be greatly appreciated.

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-10-08 : 19:57:29
see

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/dynamic-crosstab-with-multiple-pivot-columns.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tudorn
Starting Member

4 Posts

Posted - 2013-01-06 : 04:28:48
Thank you Visakh.
Sory I did not reply to you earlier.
Your link was exactly what I needed and it helped me with the reports.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-06 : 10:06:34
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -