I have to write stored proc to get the daily transaction for a specified date. Right now what i do is everytime i log a transaction in table3 I update table 2 with the count. Then i use table 2 to write the stored proc and to get the desired result. I have pasted my stored proc below with the output. My problem is when another subsystem is added in the AppInfo table i need to update my stored proc because i have hardcoded the subsystem name. Can you please show me a better way to do this. Table1:AppInfoAppId SubSystem1 Dev2 Test3 ProdTable2:TransactionCountId Appid LogDate DailyCount----------------------------------------------------------1 1 11/9/2010 12:00:00 AM 22 2 11/9/2010 12:00:00 AM 13 3 11/9/2010 12:00:00 AM 14 1 11/19/2010 12:00:00 AM 25 2 11/19/2010 12:00:00 AM 16 3 11/19/2010 12:00:00 AM 1Table3: LoggedTransactionsId AppId LogDate------------------------------------------1 1 11/9/2010 12:00:00 AM2 2 11/9/2010 12:00:00 AM3 1 11/9/2010 1:00:00 PM4 3 11/9/2010 2:00:00 PM5 1 11/19/2010 12:00:00 AM6 2 11/19/2010 12:00:00 AM7 1 11/19/2010 1:00:00 PM8 3 11/19/2010 2:00:00 PMStored Proc DailyTransCnt @FromDate datetime, @ToDate datetimeSELECT LogDate, ISNULL([Dev],0) AS Dev, ISNULL([Test],0) AS Test, ISNULL([Prod],0) AS Prod FROM (SELECT LogDate, SubSystem, DailyCount from appInfo A INNER JOIN TransactionCount B ON A.AppId=B.AppId where (logdate >= @FromDate and logdate < DateAdd(dd,1,@ToDate)) )ps PIVOT ( SUM (DailyCount) FOR [SubSystem] IN ( [Dev], [Test], [Prod]) ) AS pvResult after executing stored proc----------------------------------Logdate Dev Test Prod-----------------------------------2010-11-9 2 1 12010-11-19 2 1 1