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
 Development Tools
 ASP.NET
 Sql statements

Author  Topic 

Iain Duthie
Starting Member

17 Posts

Posted - 2005-01-14 : 09:26:48
I have a multiple sql statement that is used to delete a row of data from a database. At the moment it only deletes rows that have no blank cells but I need it to also delete rows with blank cells. I was wondering if someone could point me in the right direction.

Cheers
Iain.

jhermiz

3564 Posts

Posted - 2005-01-14 : 10:58:27
So you want to delete all rows ?



Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]


Go to Top of Page

Iain Duthie
Starting Member

17 Posts

Posted - 2005-01-14 : 11:28:19
No I have a check box attached to each row and when I check a box it search deletes that one but only if there is text in all the cells.
Go to Top of Page

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2005-01-14 : 16:14:20
Maybe you could post the SQL statement your using now?

===============================================
Creating tomorrow's legacy systems today.
One crisis at a time.
Go to Top of Page

Iain Duthie
Starting Member

17 Posts

Posted - 2005-01-17 : 04:08:02
SqlCommand sqlCmd = new SqlCommand("DELETE from catalog_list WHERE ((format = '"
+ format[i].ToString() + "')AND(drawing_no = '" + drawing_no[i].ToString() +
"')AND(group_code = '" + group_code[i].ToString() + "')AND(title = '" +
title[i].ToString() + "')AND(drawn_by = '" + drawn_by[i].ToString() +
"')AND(area = '" + area[i].ToString() + "')AND(sheetno = '" +
sheetno[i].ToString() + "')AND(total_sheets = '" + total_sheets[i].ToString() +
"')AND(location = '" + location[i].ToString() + "'))" ,sqlConnection1);

sqlCmd.Connection = sqlConnection1;
sqlConnection1.Open();
sqlCmd.ExecuteNonQuery();
sqlConnection1.Close();
Go to Top of Page

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2005-01-17 : 09:59:55
Hmmm. Let me phrase my question a little differently. Can you post the SQL statement that this generates?

===============================================
Creating tomorrow's legacy systems today.
One crisis at a time.
Go to Top of Page

Iain Duthie
Starting Member

17 Posts

Posted - 2005-01-18 : 09:46:31
It deletes the row, but only if there are no empty cells. If there is an empty cell it doesn't do anything.
Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2005-01-18 : 15:19:52
The problem is that the DELETE statement is trying to find which row to delete based on a match of the contents of the cells. The problem (other than this being a dangerous way to do deletes) is that if a row actually does not contain data (is null) your statement is treating that like an empty string, which is not necessarily the same thing. So you do not get a match. NULL does not equal NULL. You test for Null by using IS NULL or IS NOT NULL.

BUT the better way to issue this delete statement would be to provide the Primary Key as your WHERE clause rather than the contents of the row.

---------------------------------------------------------------------------------
Infoneering: Information Technology solutions engineered to professional standards.
Go to Top of Page

jhermiz

3564 Posts

Posted - 2005-01-18 : 18:46:28
Might want to make this a stored procedure as well.




Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]


Go to Top of Page

Iain Duthie
Starting Member

17 Posts

Posted - 2005-01-20 : 09:12:21
The problem with making the primary the where clause is that a lot of the data is duplicated.
Go to Top of Page

Iain Duthie
Starting Member

17 Posts

Posted - 2005-01-21 : 09:49:14
I have got it working now thank you for your help

Cheers
Iain
Go to Top of Page
   

- Advertisement -