update field on a select query

  • I have a sql query that runs on demand to generate a report. I want to update a field REPORTSENT to a Y on the selected results.

    So the next time the report is requested only the Records with a REPORTSENT = N will be returned. Normally would run the query for the records and then an update with the same where clause to mark the REPORTSENT = Y. I was hoping that there would be a way to do it in one process.

  • Do it in the other order.  Use UPDATE to update the records using the OUTPUT clause to output your required fields.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Drew's suggestion is the way forward. Here is an article which demonstrates the technique:

    https://www.sqlservercentral.com/articles/the-output-clause-for-update-statements

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Thank you for pointing me to a solution.

  • This was removed by the editor as SPAM

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply