DECLARE	cur CURSOR
	FOR select username,sessid from radiusdat
	WHERE  callstart > CONVERT(DATETIME,'Jan 1 2003')
	ORDER BY username, sessid

DECLARE	@username	VARCHAR(128)
DECLARE	@sessid		VARCHAR(128)

DECLARE	@username1	VARCHAR(128)
DECLARE	@sessid1	VARCHAR(128)


	SELECT	@username1 = ''
	SELECT	@sessid1 = ''

	/*
	** Open cursor
	*/
	OPEN	cur

	FETCH FROM cur INTO @username,@sessid

	WHILE ( @@FETCH_STATUS = 0)
	BEGIN
/*
		PRINT	@username
		PRINT	@sessid
*/

		IF ( (@username <> @username1) OR (@sessid <> @sessid1) )
		BEGIN
			SELECT @username1 = @username
			SELECT @sessid1 = @sessid
		END

		FETCH FROM cur INTO @username,@sessid

		IF ( @@FETCH_STATUS <> 0  )
			BREAK

		IF ( (@username = @username1) AND (@sessid = @sessid1) )
		BEGIN

			DELETE FROM radiusdat WHERE CURRENT OF cur
/*
			PRINT	"To be deleted"
			PRINT	@username
			PRINT	@sessid
*/
		END
	END

	CLOSE		cur
	DEALLOCATE	cur

/*
SELECT	username,sessid FROM radiusdat
	WHERE username = 'Thetlach' AND callstart > CONVERT(DATETIME,'Jan 1 2003')
*/
COMMIT


/*
sp_help radiusdat
select distinct sessid, username from radiusdat
	where username = 'Thetlach'

select * from radiusdat
	where username = 'Thetlach' and
	sessid in (select distinct sessid from radiusdat where username = 'Thetlach')
	order by sessid,username,callstart
*/

