using sp_MSForEachTable to delete data with a where clause [modified]
-
Hi All, I wanted to use the undocumented SP sp_MSForEachTable to selectively delete data from tables. So in short i want to achieve something like this using sp_MSForEachTable. delete from TableName where Date = '2007-01-03' I looked at various queries on the internet using sp_MSForEachTable, but was not able to find out the usage of sp_MSForEachTable with a "Where" clause, so if anybody has the query or links request to post it here. All that I found was to delete all data from all the tables in the db. I tried using the @whereand option like this, but the got an error saying Invalid column: SomeDate. I have this column in all the tables in that database. I did a quick check looping thro all the tables using cursors and that works fine. EXEC sp_MSForEachTable @command1='DELETE FROM ?' ,@whereand='and SomeDate = "2007-01-15"' Thanks. PJ -- modified at 14:39 Monday 15th January, 2007