Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
velnias2010
Posting Yak Master
125 Posts |
Posted - 2011-07-15 : 07:32:40
|
| Hey I want a stored procedure as follows :1) First performs a select with several parameters, and for every record in this perform and update on that recordCREATE PROCEDURE [dbo].[spGetRowIdUserHistoryToSetExpiryDate]( //These are my four parameters @userId INT = default, @programmeId INT = default, @stepId INT = default, @dayIncrease INT)ASBEGINSET NOCOUNT ON;//This is my selectSELECT id,dateAddedFROM tblUserQuestionnaireHistoryWHERE (userId = @userId) AND (programmeId = @programmeId) and stepId = @stepId and success = 1END//For every dateAdded and Id returned above I want tocreate a new variable @UpdatedDate which is dateAdded + my variable @dayIncrease update tblUserQuestionnaireHistory set dateExpired = @UpdatedDate where id = @id |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-07-15 : 08:06:20
|
You should be able to do the update in a single operation as follows:UPDATE tblUserQuestionnaireHistorySET dateExpired = dateAdded + @dayIncreaseWHERE userId = @userId AND programmeId = @programmeId AND stepId = @stepId AND success = 1 |
 |
|
|
|
|
|