• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

SQL Server 2005 Update statement in a stored procedure.

Just for grins...

Is there a "makes-sense" way to blend the two update statements below into one?

Begin

update tblSchedule
set sent = 1,
schedStatus = 'ACTIVE',
lastSendDate = getDate(),
nextSendDate = nextSendDate + (recurrEvery * recurTypeNum)
where schedStatus  = 'SEND'
end

begin
update tblSchedule
set schedStatus = 'ARCHIVE'
where endSchedDate > getdate()
end
0
lrbrister
Asked:
lrbrister
  • 2
2 Solutions
 
Aneesh RetnakaranDatabase AdministratorCommented:
Yup, it seems ok


Begin tran

update tblSchedule
set sent = 1,
schedStatus = 'ACTIVE',
lastSendDate = getDate(),
nextSendDate = nextSendDate + (recurrEvery * recurTypeNum)
where schedStatus  = 'SEND'

update tblSchedule
set schedStatus = 'ARCHIVE'
where endSchedDate > getdate()
COMMIT TRAN
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
what about this:

update tblSchedule
set sent = case when schedStatus  = 'SEND' then 1 else sent end,
schedStatus = 'ACTIVE',
lastSendDate = case when schedStatus  = 'SEND' then getDate() else lastSendDate end,
nextSendDate = case when schedStatus  = 'SEND' then nextSendDate + (recurrEvery * recurTypeNum) else nextSendDate  end
where schedStatus  = 'SEND'
   or endSchedDate > getdate()
0
 
lrbristerAuthor Commented:
aneeshattingal: and angelIII:
  Both you guys are great...any reason why I shouldn't accept both?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>any reason why I shouldn't accept both?
that's up to you
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now