Hi friend,
Don't use Cursor... try this as follows
before start check your Query Properly, because your are going to delete 14 tables, If anything wrongly Deleted then problem. So take Data Backup and check the statement.
DECLARE @AFSAccount TABLE(AccountID INT)
INSERT INTO @AFSAccount (AccountID)
SELECT AccountID FROM AFS_Account WHERE AccountID like 'Y%' and EffectiveTo is null
DELETE T1 FROM table1 T1 INNER JOIN @AFSAccount AFS ON AFS.AccountID=T1.AccountID
DELETE T2 FROM table2 T2 INNER JOIN @AFSAccount AFS ON AFS.AccountID=T2.AccountID
DELETE T3 FROM table3 T3 INNER JOIN @AFSAccount AFS ON AFS.AccountID=T3.AccountID
DELETE T4 FROM table4 T4 INNER JOIN @AFSAccount AFS ON AFS.AccountID=T4.AccountID
DELETE T5 FROM table5 T5 INNER JOIN @AFSAccount AFS ON AFS.AccountID=T5.AccountID
DELETE T6 FROM table6 T6 INNER JOIN @AFSAccount AFS ON AFS.AccountID=T6.AccountID
DELETE T7 FROM table7 T7 INNER JOIN @AFSAccount AFS ON AFS.AccountID=T7.AccountID
DELETE T8 FROM table8 T8 INNER JOIN @AFSAccount AFS ON AFS.AccountID=T8.AccountID
DELETE T9 FROM table9 T9 INNER JOIN @AFSAccount AFS ON AFS.AccountID=T9.AccountID
DELETE T10 FROM table10 T10 INNER JOIN @AFSAccount AFS ON AFS.AccountID=T10.AccountID
DELETE T11 FROM table11 T11 INNER JOIN @AFSAccount AFS ON AFS.AccountID=T11.AccountID
DELETE T12 FROM table12 T12 INNER JOIN @AFSAccount AFS ON AFS.AccountID=T12.AccountID
DELETE T13 FROM table13 T13 INNER JOIN @AFSAccount AFS ON AFS.AccountID=T13.AccountID
DELETE T14 FROM table14 T14 INNER JOIN @AFSAccount AFS ON AFS.AccountID=T14.AccountID
Regards,
GVPrabu