CREATE	TABLE dups__radius	(
		username	VARCHAR(128),
		sessid		VARCHAR(128),
		callstart	DATETIME,
		callend		DATETIME,
		data_in		NUMERIC,
		data_out	NUMERIC
				)
go

TRUNCATE TABLE dups__radius
go

DECLARE	cur CURSOR
	FOR SELECT username,sessid,callstart,callend,data_in,data_out FROM radiusdat
	WHERE  callstart > CONVERT(DATETIME,'Jun 1 2003')
	ORDER BY username, sessid

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

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

DECLARE	@callstart	DATETIME
DECLARE	@callend	DATETIME

DECLARE	@data_in	NUMERIC
DECLARE	@data_out	NUMERIC


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

	/*
	** Open cursor
	*/
	OPEN	cur

	FETCH FROM cur INTO @username,@sessid,@callstart,@callend,@data_in,@data_out

	WHILE ( @@FETCH_STATUS = 0)
	BEGIN

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

		FETCH FROM cur INTO @username,@sessid,@callstart,@callend,@data_in,@data_out

		IF ( @@FETCH_STATUS <> 0  )
			BREAK

		IF ( (@username = @username1) AND (@sessid = @sessid1) )
		BEGIN
/*
			DELETE FROM radiusdat WHERE CURRENT OF cur
*/

			INSERT	INTO dups__radius VALUES (@username,@sessid,@callstart,@callend,@data_in,@data_out);

/*
			PRINT	"To be deleted"
			PRINT	@username
			PRINT	@sessid
*/

		END
	END

	CLOSE		cur
	DEALLOCATE	cur

	SELECT	* FROM dups__radius


