Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Group of Records?? 1

Status
Not open for further replies.

byrne1

Programmer
Aug 7, 2001
415
US
The following SQL query returns three records. I want to update the timerecstatus field of the records that are returned by this query to 'C'. How can I modify this SQL query to do this in one step?

select projectcustid
from ((timerec
left join task on taskid=timerectaskid)
left join story on task.storyid=story.storyid)
left join project on project.projectid=story.projectid
where timerecstatus='n' and projectcustid='wgs'
 
update projectcustid set timerecstatus='c'
from ((timerec
left join task on taskid=timerectaskid)
left join story on task.storyid=story.storyid)
left join project on project.projectid=story.projectid
where timerecstatus='n' and projectcustid='wgs'
 
Try this. If it works, change the rollback to commit:

Begin Transaction
--- check rows before update
select *
from ((timerec
left join task on taskid=timerectaskid)
left join story on task.storyid=story.storyid)
left join project on project.projectid=story.projectid
where timerecstatus='n' and projectcustid='wgs'

update timerec
set timerecstatus = 'C'
from ((timerec
left join task on taskid=timerectaskid)
left join story on task.storyid=story.storyid)
left join project on project.projectid=story.projectid
where timerecstatus='n' and projectcustid='wgs'

--- check rows after update

select *
from ((timerec
left join task on taskid=timerectaskid)
left join story on task.storyid=story.storyid)
left join project on project.projectid=story.projectid
where timerecstatus='n' and projectcustid='wgs'

Rollback Transaction

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top