Im using SQL 7.0 and deleting a rows with cursor from user tables. If productID in exists in one of my ProductHistory tables and if the productID in the master table "Products" is less than a certain date then I want to delete it. I get an error msg (follows):
Server: Msg 137, Level 15, State 2, Line 14
Must declare the variable '@tablename.
Any ideas?
--------------------------------------------------------------------------------------------------------------
DECLARE @tablename sysname
DECLARE cur CURSOR FOR
Select [name] from sysobjects where xtype = 'U' and [name] like 'ProdHis%'
OPEN cur
FETCH NEXT FROM cur INTO @tablename
WHILE @@FETCH_STATUS = 0
BEGIN
delete from @tablename
where ProductID in (select ProductID from Products
where (ShelfLife <= CONVERT(DATETIME,'2005-03-31 00:00:00', 102)))
FETCH NEXT FROM cur INTO @tablename
END
CLOSE cur
DEALLOCATE cur
Server: Msg 137, Level 15, State 2, Line 14
Must declare the variable '@tablename.
Any ideas?
--------------------------------------------------------------------------------------------------------------
DECLARE @tablename sysname
DECLARE cur CURSOR FOR
Select [name] from sysobjects where xtype = 'U' and [name] like 'ProdHis%'
OPEN cur
FETCH NEXT FROM cur INTO @tablename
WHILE @@FETCH_STATUS = 0
BEGIN
delete from @tablename
where ProductID in (select ProductID from Products
where (ShelfLife <= CONVERT(DATETIME,'2005-03-31 00:00:00', 102)))
FETCH NEXT FROM cur INTO @tablename
END
CLOSE cur
DEALLOCATE cur