## How to calculate total sum of these table

 Author Message raghuldrag Ten Centuries Group: General Forum Members Points: 1290 Visits: 573 Hi Friends i ve the table like create table accutn_det( fs_locn char(50), fs_accno varchar(100),fs_cost_center varchar(100), fs_tran_type char(50) fs_amount numeric(50), fs_trans_date datetime,)insert into accutn_det values('CHN','E-Sw-2100','205produ','Cr','5000','2014-05-01')values('CHN','E-Sw-2100','205produ','Dr','15000','2014-05-06')values('HYD','E-Sw-2100','206produ','Dr','8000','2014-05-03')values('BANG','E-Sw-2100','208produ','Dr','25000','2014-05-01')values('BANG','E-Sw-2100','208produ','Cr','5000','2014-05-06')like all loctaion details stored from all months in these table here Dr=debit,Cr=Credit Formula= 'Dr-Cr' to find the salary wavges of amountso i made the query to find the amount for mayselect fs_locn, fs_accno, amount=sum(case when fs_accno like 'E%' and fs_tran_type='Dr' then fs_amount when fs_accno like 'E%' and fs_tran_type='Cr' then fs_amount * -1 end )from accutn_det where fs_trans_date between '01-may-2014' and '31-may-2014'groupby fs_locn,fs_accnonow i need the sum values of all costcenter for the particular accounthow to do that? Koen Verbeeck SSC Guru Group: General Forum Members Points: 146458 Visits: 13350 Add the cost center in the GROUP BY? How to post forum questions.Need an answer? No, you need a question.What’s the deal with Excel & SSIS?My blog at SQLKover.MCSE Business Intelligence - Microsoft Data Platform MVP Hardy21 SSCertifiable Group: General Forum Members Points: 5600 Visits: 1399 Add Cost center (fs_cost_center) in Group by clause. Thanks raghuldrag Ten Centuries Group: General Forum Members Points: 1290 Visits: 573 Hi Friends i need out put likefor exmaple :account no 205prod 206prod totalE-SW-100 10000 3000 13000how make code? Koen Verbeeck SSC Guru Group: General Forum Members Points: 146458 Visits: 13350 raghuldrag (7/11/2014)Hi Friends i need out put likeaccount no 205prod 206prod totalE-SW-100 10000 3000 13000how make code?How is the 3000 calculated? How to post forum questions.Need an answer? No, you need a question.What’s the deal with Excel & SSIS?My blog at SQLKover.MCSE Business Intelligence - Microsoft Data Platform MVP raghuldrag Ten Centuries Group: General Forum Members Points: 1290 Visits: 573 Hi friends,i need the output like Accno 205produ 206produ 208produ totalE-SW-2100 15000 8000 20000 42000after find the sum of account how to calculate the total value of each costcenter for that account Koen Verbeeck SSC Guru Group: General Forum Members Points: 146458 Visits: 13350 Is it always 205, 206 and 208, or are there more columns possible? How to post forum questions.Need an answer? No, you need a question.What’s the deal with Excel & SSIS?My blog at SQLKover.MCSE Business Intelligence - Microsoft Data Platform MVP raghuldrag Ten Centuries Group: General Forum Members Points: 1290 Visits: 573 Hi Friends, The costcneter account wont be changed always same account and unique raghuldrag Ten Centuries Group: General Forum Members Points: 1290 Visits: 573 Hi Friends , i just added my code with rollupselect fs_locn, fs_accno,fs_cost_center,amount=sum(case when fs_accno like 'E%' and fs_tran_type='Dr' then fs_amountwhen fs_accno like 'E%' and fs_tran_type='Cr' then fs_amount * -1end)from accutn_det where fs_trans_date between '01-may-2014' and '31-may-2014'groupby fs_locn,fs_accno,fs_cost_center with rollupits giving the sum total value with NULLhow to avoid "Null" replace on TOTAL In That??? Hardy21 SSCertifiable Group: General Forum Members Points: 5600 Visits: 1399 Give it a try:`; WITH AccountCTE AS (SELECT fs_accno, fs_cost_center, fs_amount from accutn_det)SELECT fs_accno,[205produ],[206produ],[208produ], COALESCE([205produ], 0)+ COALESCE([206produ], 0)+ COALESCE([208produ],0) AS Total FROM AccountCTEPIVOT (SUM(fs_amount) FOR fs_cost_center IN ([205produ],[206produ],[208produ])) p` Thanks

## Permissions

 You can't post new topics. You can't post topic replies. You can't post new polls. You can't post replies to polls. You can't edit your own topics. You can't delete your own topics. You can't edit other topics. You can't delete other topics. You can't edit your own posts. You can't edit other posts. You can't delete your own posts. You can't delete other posts. You can't post events. You can't edit your own events. You can't edit other events. You can't delete your own events. You can't delete other events. You can't send private messages. You can't send emails. You can read topics. You can't vote in polls. You can't upload attachments. You can download attachments. You can't post HTML code. You can't edit HTML code. You can't post IFCode. You can't post JavaScript. You can post emoticons. You can't post or upload images.

##### Select a forum
 SQL Server 2017      SQL Server 2017 - Administration      SQL Server 2017 - Development SQL Server 2016      SQL Server 2016 - Administration      SQL Server 2016 - Development and T-SQL SQL Server 2014      Administration - SQL Server 2014      Development - SQL Server 2014 SQL Server 2012      SQL 2012 - General      SQL Server 2012 - T-SQL SQL Server vNext      SQL Server 15 - Administration      SQL Server 15 - Development SQL Server 2008      SQL Server 2008 - General      T-SQL (SS2K8)      June 2007 CTP      Working with Oracle      July CTP      SQL Server Newbies      Security (SS2K8)      SQL Server 2008 High Availability      SQL Server 2008 Administration      Data Corruption (SS2K8 / SS2K8 R2)      SQL Server 2008 Performance Tuning Cloud Computing      SQL Azure - Development      SQL Azure - Administration      Amazon AWS and other cloud vendors      General Cloud Computing Questions      CosmosDB      Azure Data Lake      Azure Machine Learning Reporting Services      Reporting Services      Reporting Services 2005 Administration      Reporting Services 2005 Development      Reporting Services 2008/R2 Administration      Reporting Services 2008 Development      SSRS 2012      SSRS 2014      SSRS 2016 Programming      Connecting      General      SMO/RMO/DMO      XML      Service Broker      Powershell      Testing      TFS/Data Dude/DBPro      SSDT      Continuous Integration, Deployment, and Delivery      R Services and R Language Data Warehousing      Integration Services      Strategies and Ideas      Analysis Services      Data Transformation Services (DTS)      Performance Point      Data Mining      PowerPivot      R language      Machine Learning Database Design      Disaster Recovery      Design Ideas and Questions      Relational Theory      Hardware      Virtualization      Security and Auditing SQLServerCentral.com      Anything that is NOT about SQL!      Contests!      Editorials      SQLServerCentral.com Announcements      SQLServerCentral.com Website Issues      Suggestions      Tag Issues with Content      Podcast Feedback      SQLServerCentral.com Test Forum      Articles Requested SQL Server 2005      Administering      Backups      Business Intelligence      CLR Integration and Programming.      Data Corruption      Development      Working with Oracle      SQL Server 2005 Compact Edition      SQL Server 2005 General Discussion      SQL Server 2005 Security      SQL Server 2005 Strategies      SS2K5 Replication      SQL Server Express      SQL Server 2005 Performance Tuning      SQL Server 2005 Integration Services      T-SQL (SS2K5)      SQL Server Newbies SQL Server 7,2000      Administration      Backups      Data Corruption      General      Globalization      In The Enterprise      Working with Oracle      Security      Strategies      SQL Server Newbies      Service Packs      SQL Server CE      Performance Tuning      Replication      Sarbanes-Oxley      T-SQL      SQL Server Agent SQL Server and other platforms      MySQL      Oracle      PostgreSQL      DB2      SQL Server and Sharepoint Older Versions of SQL (v6.5, v6.0, v4.2)      Older Versions of SQL (v6.5, v6.0, v4.2) Career      Certification      Employers and Employees      Events      Job Postings      Resumes and Job Hunters      Presentations and Speaking      Retired Members Testing Center      SQL Server Security Skills      Question of the Day (QOD) Microsoft Access      Microsoft Access Products and Books      Third Party Products         SQLCentric         Extreme Technologies.         Innovartis         Embarcadero         SQL Sentry         Sonasoft         Golden Gate Software         Idera         Lumigent         Red Gate Software         ApexSQL         Quest Software         CA      Discussions about Books         Discuss Programming Books          Discuss XML Books          Discuss T-SQL Books          Discuss Data Warehousing Books          Discuss DTS Books          Discuss SQL Server 2000 Books         Discuss SQL Server 7.0 Books Notification Services      Administration Article Discussions Future Versions      SQL 12