Hello, I have 3 tables with rows, which I want to delete from another table. I want to delete all rows from this table using first one, then second one and then third one table step by stepI want to use a function, smth like this:create function DeleteRows (@ItemName varchar(100))returns void asbegindelete from Table1 where ItemName=@ItemNameend
Then I can call this function in a loop using @ItemName from one of 3 tables.the problem here, as I understood, is that I can't use VOID as return type in Transact-SQL..I tried to change syntax, but still got errors..Maybe I can use stored procedure, like this:create stored procedure DeleteRows (@ItemName varchar(100))asbegindelete from Table1 where ItemName=@ItemNameend
BUT I can't execute it in loop, is it because I must substitute certain string here, like 'AUSTRALIA'??here is the code:declare @counter int;declare @name varchar(100);set @counter=1while counter<=(select count(ItemID) from Table2)beginselect @name=(select ItemName from Table2 where ItemID=@counter)execute DeleteRows(@name) <--------------HERE!@counter=@counter+1end
Is there any way to call this procedure in such loop, or maybe I need another solution.Help me, please