I have a table that contain memberId’s but they do not run concurrently.
How must I loop through them?
I have this:
select mm.memberid, mm.aspnetuserid, mm.email
into #MemberIdsToDelete
from membership.members as mm
left join aspnet_membership as asp
on mm.aspnetuserid=asp.userid
left join trade.tradesmen as tr
on tr.memberid=mm.memberid
where asp.isapproved = 0 and tr.ImportDPN IS NOT NULL and tr.importDPN <> ''
order by mm.memberid
ALTER TABLE #MemberIdsToDelete ADD id int NOT NULL AUTO_INCREMENT
DECLARE @MaxRownum int
SET @MaxRownum = (SELECT MAX(id) FROM MemberIdsToDelete)
WHILE @Iter <= @MaxRownum
-- do things
SET @Iter = @Iter + 1
END
The above is not correct, I get error on the alter table line obviously:
Incorrect syntax near ‘AUTO_INCREMENT’
You can use cursors to loop through table, something like this: