## Remove Grand Total Row......

 Author Message Grass SSC Veteran Group: General Forum Members Points: 225 Visits: 342 Hi all,I am trying to see if any one can help me on how to remove a grand total row from a table. I have a table in which there are 6 columns. first 3 columns there is some data but at first 3 columns, last row is blank and the last 3 columns have data which is added at the last 3 row as a grand total. here it is looks like:col1 col2 col3 col4 col5 col6a b c 1 2 5d e f 4 3 8g h i 6 7 5 11 12 18So, the last three column row is grand total and the first 3 columns last row is blank. So, I am trying to delete that but can't.Need helpThanks. WolfgangE Ten Centuries Group: General Forum Members Points: 1293 Visits: 798 I don't understand your explanations. Post some example data and try to explain again using these data. Grass SSC Veteran Group: General Forum Members Points: 225 Visits: 342 I mean my question is that a table have some columns and at the row there is a grand total of a data in the above column. So, if i have 4 columns and the last two columns each row have some numbers which will add at the last row as a total number. The other columns have data also but the last row first two columns doesnt have anything in it just blanks. how to remove the last row.thanks.col1 col2 col3 col4 col5 col6a b c 1 2 5d e f 4 3 8g h i 6 7 5 11 12 18 WolfgangE Ten Centuries Group: General Forum Members Points: 1293 Visits: 798 You say the rows with the total contain blanks in the first two columns, the other rows do not. So if this is your criteria the query is quite easy:`select * from dbo.TableXwhere col1 = '' and col2 = ''`Try this select to check if it returns the rows you want to delete. If so replace the "select *" by "delete" and these rows will be deleted.`delete from dbo.TableXwhere col1 = '' and col2 = ''` Grass SSC Veteran Group: General Forum Members Points: 225 Visits: 342 OK. You its right if I use this statement to delete this it will delete it. The whole purpose is that I want the last row to be deleted where the grand total of numbers and blank spaces on the other two columns. So if there is another row with blank spaces shows in the two columns.Is it going to delete those rows with this statement?If it does then I don't think this statement will work. WolfgangE Ten Centuries Group: General Forum Members Points: 1293 Visits: 798 I'm still not sure, but yes, the statement above deletes ALL rows that contain the free spaces in the two columns.If you only want delete the last row there are several possibilities. For the beginning I wold take an easy way. Using the top clause you can select the primary key value of the "last row" in your table. Then you can delete the row using the primary key value.Let's say there is a column InsertDate in your table und you want to delete only the last inserted row with blanks. Let's also say there is a primary key column Named "Id" in your table.This would be:`declare @IdToDelete int;select @IdToDelete = ( select top (1) Id from dbo.TableX where col1 = '' and col2 = '' order by InsertDate desc )delete from dbo.TableX where Id = @IdToDelete`Again use a select instead of a delete statement to check the rows the query returns.For a more exactly reply you really should post the table structure you use and some sample data.

## 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 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 14 - Administration      SQL Server 14 - 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 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 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      Question of the Day (QOD)      SQL Server Security Skills Microsoft Access      Microsoft Access Products and Books      Third Party Products         CA         Extreme Technologies.         Innovartis         Embarcadero         SQL Sentry         Sonasoft         SQLCentric         Golden Gate Software         Lumigent         Red Gate Software         Quest Software         ApexSQL         Idera      Discussions about Books         Discuss Programming Books          Discuss XML Books          Discuss T-SQL Books          Discuss Data Warehousing Books          Discuss DTS Books          Discuss SQL Server 7.0 Books         Discuss SQL Server 2000 Books Notification Services      Administration Article Discussions Future Versions      SQL 12