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 2005 Forums
 Transact-SQL (2005)
 Pivot Tables

Author  Topic 

lemondash
Posting Yak Master

159 Posts

Posted - 2010-03-01 : 09:56:43
Pivot tables.

I have inherited a rather old database. The problem I’m currently having is with a rather large table which data gets added to every single day. The table itself that has the problem pretty much consist of four columns, please see below.
(CompanyName,Date,Partentcode,ChildCode)
As I mention before the data gets imported daily and the values don’t get updated if they change it just inserts a new row, so after a while the table gets rather big with data that doesn’t need to be in there.
What somebody has asked me to do is to create a report looking grid with the Patent Codes, ChildCode at the top and the company name down by the side and then to have the date field as the value, bit like a pivot table. Can this be done with the pivot function from Sql Server?

The query below should give me the exact data i need, but I’m not able to put the data in as a value.
SELECT
[CompanyName] ,
MAX([Date]) ,
[ParentCode] ,
[ChildCode]
FROM dbo.tb_ICB_if
GROUP BY [Security NAME] ,
[ParentCode] ,
[ChildCode]

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-01 : 10:25:38
you can do that. do you want the codes to be determined dynamically or will they be same always?

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

Go to Top of Page

lemondash
Posting Yak Master

159 Posts

Posted - 2010-03-01 : 10:55:42
dynamically would be great, but either would be a great help.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-01 : 10:58:36
see

http://beyondrelational.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx

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

Go to Top of Page

lemondash
Posting Yak Master

159 Posts

Posted - 2010-03-01 : 12:23:37
Excellent i check it out
Go to Top of Page
   

- Advertisement -