views:

32

answers:

1

i have a contact us table containing name emailid phoneno message repliedmessage as fields, by default the replied message field is null after replying to a particular message i am updating that field but at the same time i also want to retrieve the other values also like name and emailid using select statements

+1  A: 

Are you saying you are updating multiple rows or only one?

If you're updating multiple rows, you could select the affected row IDs into a temp table, perform the update, then return a join of the tmp table's IDs on the updated table.

If you're updating a single row, just perform a select on that row after the update.

It is bad for maintainability to try two operations at the same time, unless the logic of the situation makes it clear, later on, that it is required.

You could always have a simple LastUpdated DATETIME field on the table. Then you just need a variable which you set to getdate() and use during the update. After the update simply return every row which where LastUpdated matches the datetime variable.

Eg:

declare @opTime datetime
set @opTime = getdate()

update .... (...., LastUpdated) values (....., @opTime)

select * from ... where LastUpdated = @opTime
Matt W