You have to store your already returned result somewhere (for eaxample in another table) and then add a LEFT JOIN to check the value does not exist.
Here's the table
CREATE table AlreadyReturned
(
Id int,
UserName varchar(200)
)
And here's the code:
DECLARE @Q_ID int
// @Username will be passed as a paremeter of course, here
// it is set for simplicity
DECLARE @Username varchar(200)
SET @Username = 'test'
WHILE @Q_ID IS NULL
BEGIN
SET @Q_ID=(
SELECT Top 1 MyTable.[No]
FROM MyTable LEFT OUTER JOIN AlreadyReturned
ON MyTable.[No] = AlreadyReturned.Id AND AlreadyReturned.UserName = @UserName
WHERE AlreadyReturned.Id IS NULL order by NEWID())
IF @Q_ID IS NULL
DELETE FROM AlreadyReturned WHERE UserName = @Username
END
INSERT INTO AlreadyReturned VALUES (@Q_ID, @Username)
SELECT @Q_ID
Take care this code is like a "Time Bomb", as it works until the AlreadyReturned table does not contain all the values that are present in the MyTable table