IN SQL, I need an extra row at the very bottom to show the total for each column in order to get a summary for each row. How do I do that? Below is my query.

--Page 1.5: My Financials – Accounts Receivable--Still needs grand total of each columnDeclare @Attorney varchar(5),@Type varchar(10); --(B) Billing or (W) WorkingSET @Attorney = '02500'SET @Type = 'B'IF @Type = 'W'--WORKINGBEGINselect tkinit as WA_ID, tklast+', ' + tkfirst as WA_name,clnum as Client_id,clname1 as Client_name,mmatter as Matter_id,mdesc1 as Matter_name,convert(decimal(11,2),round (sum(arfbal+arcbal),2)) AS Total_AR,convert(decimal(11,2),round (sum(arf1+arc1),2)) as AR_0_30,convert(decimal(11,2),round (sum(arf2+arc2),2)) as AR_31_60,convert(decimal(11,2),round (sum(arf3+arc3),2)) AS AR_61_90,convert(decimal(11,2),round (sum(udf19+udf20),2)) as AR_91_120,convert(decimal(11,2),round (sum((arf4+arc4)-(udf19+udf20)),2)) as AR_121_180,convert(decimal(11,2),round (sum(arf5+arc5),2)) as AR_181_365,convert(decimal(11,2),round (sum(arf6+arc6),2)) as AR_over_365from df_dwtkmat, df_dwcontrol, timekeep, matter, clientwhere matter=mmatterand mclient=clnumand watty=tkinitand rectype=4020and pe=defvalueand watty=@Attorneygroup by tkinit, tklast+', ' + tkfirst,clnum,clname1,mmatter,mdesc1having sum(arfbal+arcbal)<>0order by tkinit, tklast+', ' + tkfirst,clnum,clname1,mmatter,mdesc1ENDELSEBEGIN --by Billing Partnerselect tkinit as BP_ID, tklast+', ' + tkfirst as BP_name,clnum as Client_id,clname1 as Client_name,mmatter as Matter_id,mdesc1 as Matter_name,convert(decimal(11,2),round (sum(arfbal+arcbal),2)) AS Total_AR,convert(decimal(11,2),round (sum(arf1+arc1),2)) as AR_0_30,convert(decimal(11,2),round (sum(arf2+arc2),2)) as AR_31_60,convert(decimal(11,2),round (sum(arf3+arc3),2)) AS AR_61_90,convert(decimal(11,2),round (sum(udf19+udf20),2)) as AR_91_120,convert(decimal(11,2),round (sum((arf4+arc4)-(udf19+udf20)),2)) as AR_121_180,convert(decimal(11,2),round (sum(arf5+arc5),2)) as AR_181_365,convert(decimal(11,2),round (sum(arf6+arc6),2)) as AR_over_365from df_dwmatter, df_dwcontrol, timekeep, matter, clientwhere matter=mmatterand mclient=clnumand mbillaty=tkinitand rectype=4020and pe=defvalueand mbillaty=@Attorneygroup by tkinit, tklast+', ' + tkfirst,clnum,clname1,mmatter,mdesc1having sum(arfbal+arcbal)<>0order by tkinit, tklast+', ' + tkfirst,clnum,clname1,mmatter,mdesc1END

select tkinit as WA_ID, tklast+', ' + tkfirst as WA_name,clnum as Client_id,clname1 as Client_name,mmatter as Matter_id,mdesc1 as Matter_name,convert(decimal(11,2),round (sum(arfbal+arcbal),2)) AS Total_AR,convert(decimal(11,2),round (sum(arf1+arc1),2)) as AR_0_30,convert(decimal(11,2),round (sum(arf2+arc2),2)) as AR_31_60,convert(decimal(11,2),round (sum(arf3+arc3),2)) AS AR_61_90,convert(decimal(11,2),round (sum(udf19+udf20),2)) as AR_91_120,convert(decimal(11,2),round (sum((arf4+arc4)-(udf19+udf20)),2)) as AR_121_180,convert(decimal(11,2),round (sum(arf5+arc5),2)) as AR_181_365,convert(decimal(11,2),round (sum(arf6+arc6),2)) as AR_over_365from df_dwtkmat, df_dwcontrol, timekeep, matter, clientwhere matter=mmatterand mclient=clnumand watty=tkinitand rectype=4020and pe=defvalueand watty=@Attorneygroup by tkinit, tklast+', ' + tkfirst,clnum,clname1,mmatter,mdesc1having sum(arfbal+arcbal)<>0order by tkinit, tklast+', ' + tkfirst,clnum,clname1,mmatter,mdesc1with rollup

with rollup gives me the following error in the sql query:

Msg 156, Level 15, State 1, Line 49
Incorrect syntax near the keyword 'END'.
Msg 156, Level 15, State 1, Line 84
Incorrect syntax near the keyword 'END'.

it did not like the with rollup syntax for some reason.

select tkinit as WA_ID, tklast+', ' + tkfirst as WA_name,clnum as Client_id,clname1 as Client_name,mmatter as Matter_id,mdesc1 as Matter_name,convert(decimal(11,2),round (sum(arfbal+arcbal),2)) AS Total_AR,convert(decimal(11,2),round (sum(arf1+arc1),2)) as AR_0_30,convert(decimal(11,2),round (sum(arf2+arc2),2)) as AR_31_60,convert(decimal(11,2),round (sum(arf3+arc3),2)) AS AR_61_90,convert(decimal(11,2),round (sum(udf19+udf20),2)) as AR_91_120,convert(decimal(11,2),round (sum((arf4+arc4)-(udf19+udf20)),2)) as AR_121_180,convert(decimal(11,2),round (sum(arf5+arc5),2)) as AR_181_365,convert(decimal(11,2),round (sum(arf6+arc6),2)) as AR_over_365from df_dwtkmat, df_dwcontrol, timekeep, matter, clientwhere matter=mmatterand mclient=clnumand watty=tkinitand rectype=4020and pe=defvalueand watty=@Attorneygroup by tkinit, tklast+', ' + tkfirst,clnum,clname1,mmatter,mdesc1having sum(arfbal+arcbal)<>0union allselect 0 as WA_ID, 'total' as WA_name,0,'',0,0,convert(decimal(11,2),round (sum(arfbal+arcbal),2)) AS Total_AR,convert(decimal(11,2),round (sum(arf1+arc1),2)) as AR_0_30,convert(decimal(11,2),round (sum(arf2+arc2),2)) as AR_31_60,convert(decimal(11,2),round (sum(arf3+arc3),2)) AS AR_61_90,convert(decimal(11,2),round (sum(udf19+udf20),2)) as AR_91_120,convert(decimal(11,2),round (sum((arf4+arc4)-(udf19+udf20)),2)) as AR_121_180,convert(decimal(11,2),round (sum(arf5+arc5),2)) as AR_181_365,convert(decimal(11,2),round (sum(arf6+arc6),2)) as AR_over_365from df_dwtkmat, df_dwcontrol, timekeep, matter, clientwhere matter=mmatterand mclient=clnumand watty=tkinitand rectype=4020and pe=defvalueand watty=@Attorneyhaving sum(arfbal+arcbal)<>0order by tkinit, tklast+', ' + tkfirst,clnum,clname1,mmatter,mdesc1

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…

This article explains how to reset the password of the sa account on a Microsoft SQL Server. The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.