Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
noonz
Starting Member
33 Posts |
Posted - 2010-07-23 : 12:25:07
|
Can someone help me rewrite this SP to run it on the "LastActivity" column of the cs_Users table, I want it to run it where LastActivity < 2010-01-01DECLARE mycursor CURSOR FORSELECT UserID, UserNameFROM cs_UsersWHERE ((UserName <> 'cek') AND (UserName <> 'charlie') AND (UserName <> 'Anonymous'))ORDER BY UserName DESC;OPEN mycursor;DECLARE @id INT, @name VARCHAR(80), @count INT;SET @count = 0;FETCH NEXT FROM mycursor INTO @id, @nameWHILE @@FETCH_STATUS = 0 BEGINPRINT 'Deleting ='+ISNULL(@name, 'NULL');EXEC dbo.cs_User_Delete @id, 'Anonymous';FETCH NEXT FROM mycursor INTO @id, @nameSET @count = @count + 1;ENDPRINT 'Number of users deleted = ' + CONVERT(VARCHAR(20),ISNULL(@count,0));CLOSE mycursorDEALLOCATE mycursor |
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-07-23 : 12:39:21
|
Try this:DECLARE mycursor CURSOR FORSELECT UserID, UserNameFROM cs_UsersWHERE UserName not in ('cek','charlie','Anonymous')And LastActivity < '2010-01-01'ORDER BY UserName DESC;OPEN mycursor;DECLARE @id INT, @name VARCHAR(80), @count INT;SET @count = 0;FETCH NEXT FROM mycursor INTO @id, @nameWHILE @@FETCH_STATUS = 0 BEGIN PRINT 'Deleting ='+ISNULL(@name, 'NULL'); EXEC dbo.cs_User_Delete @id, 'Anonymous'; FETCH NEXT FROM mycursor INTO @id, @name SET @count = @count + 1;ENDPRINT 'Number of users deleted = ' + CONVERT(VARCHAR(20),ISNULL(@count,0));CLOSE mycursorDEALLOCATE mycursorRegards,BohraI am here to learn from Masters and help new bees in learning. |
 |
|
|
|
|
|
|