问题描述:

i want to change the status of the message which i am retrieving.

consider a MySQL database with three column message,username and status.

from this table i am retrieving the message which are all having the status 1.

for example i am retrieving the message of user1 which status is 1 after retrieving that message i want to change the status of that message to 0. only the user1 message status not the others. How do i do it? Someone please answer.....

网友答案:

Just use UPDATE statement

UPDATE message_user2 
SET status = 0 
WHERE Username = 'user1'
网友答案:
UPDATE message_user2
SET message_user2.status = 0 
WHERE Username IN '(SELECT Username FROM message_user2 WHERE Username = user1)';
网友答案:

Try this

DECLARE @name VARCHAR(128)
DECLARE @SQL VARCHAR(254)
SELECT @name = (SELECT TOP 1 username FROM message_user2 WHERE username='user1' and status=1)

WHILE @name IS NOT NULL BEGIN SELECT @SQL = 'Update message_user2 set status=0 where username='[email protected] EXEC (@SQL) PRINT 'Updated value: ' + @name SELECT @name = (SELECT TOP 1 username FROM message_user2 WHERE username='user1' and status=1 ) END SELECT * from message_user2 where status=0 and username='user1' GO

相关阅读:
Top