SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Translate rown in columns
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tudorn
Starting Member

4 Posts

Posted - 10/08/2012 :  14:17:22  Show Profile  Reply with Quote

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



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

India
52249 Posts

Posted - 10/08/2012 :  19:57:29  Show Profile  Reply with Quote
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 - 01/06/2013 :  04:28:48  Show Profile  Reply with Quote
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

India
52249 Posts

Posted - 01/06/2013 :  10:06:34  Show Profile  Reply with Quote
welcome

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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000