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='+@name 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