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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Delete rows with NULL values

Author  Topic 

waxdart23
Starting Member

33 Posts

Posted - 2004-06-18 : 07:09:16
I have a table from which I wish to delete rows where a certain column is either NULL or contains the word "memo". I am using the follwing code:
DELETE FROM MASTER_ACCOUNT_MEMO WHERE isnull(MEMO, '') = NULL
GO
DELETE FROM MASTER_ACCOUNT_MEMO WHERE (MEMO = '%memo%')
GO

I have tried various versions of the code above, such as:
DELETE FROM MASTER_ACCOUNT_MEMO WHERE (MEMO = NULL)
GO
DELETE FROM MASTER_ACCOUNT_MEMO WHERE MEMO = '%memo%'
GO

When I run it, no rows are affected.
Any ideas would be appreciated.

Thanks
P

mr_mist
Grunnio

1870 Posts

Posted - 2004-06-18 : 07:20:54
[code]DELETE FROM MASTER_ACCOUNT_MEMO WHERE MEMO is null or memo like '%memo%'[/code]

Should do it. I'd test that as a SELECT first though.

-------
Moo. :)
Go to Top of Page

waxdart23
Starting Member

33 Posts

Posted - 2004-06-18 : 07:24:09
Worked a treat. Thanks very much mr_mist!

Thanks
P
Go to Top of Page

drymchaser
Aged Yak Warrior

552 Posts

Posted - 2004-06-18 : 09:11:53
For empty strings which are not NULL you could test this.

DELETE FROM MASTER_ACCOUNT_MEMO WHERE NULLIF(RTRIM(MEMO),'') is null or memo like '%memo%'

Go to Top of Page
   

- Advertisement -