Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Sql Server Programming

Select and Update in one


Is it possible to do the following in one statement:

SELECT ID
INTO #ProcessList
 FROM MyTable
 WHERE Processed = 0

 UPDATE MyTable
 SET  Processed = 1
 WHERE FeedID IN ( SELECT ID
      FROM #ProcessList )

 SELECT ID #ProcessList

 DROP TABLE #ProcessList

TIA

MattC

Using the OUTPUT direction in SQL Server 2005

UPDATE MyTable
SET  Processed = 1
OUTPUT INSERTED.FeedID AS ID
WHERE FeedID IN ( SELECT ID FROM MyTable WHERE Processed = 0)

-----------------------------------------------Reply-----------------------------------------------

Hi

try this

 update mt set Processed = 1
 from MyTable mt
 inner join(select id from MyTable  WHERE Processed = 0)rs on
rs.id=mt.FeedID

regards
VT
Knowledge is power, share it....
http://oneplace4sql.blogspot.com/

"MattC" <m@m.com> wrote in message

news:eXg5zSBqHHA.4196@TK2MSFTNGP06.phx.gbl...

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc