CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2006
    Posts
    19

    how to select a record and delete from table afterwards?

    is it possible to retrieve a record and delete it from the table afterwards,
    in a single sql statement?

    right now, i'm doing it in 2 separate sql statements:
    1. select * from table where idNum = 1 (store it in a record set variable)
    2. delete from table where idNum = 1

    i was wondering if i could execute it in a single sql statement.

    thanks,
    joe

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: how to select a record and delete from table afterwards?

    If you are using SQL 2005 then you should look at "OUTPUT DELETED" keyword on MSDN. This can be used with the delete statement to output the deleted rows into a table, etc.

  3. #3
    Join Date
    Apr 2006
    Posts
    19

    Re: how to select a record and delete from table afterwards?

    hi,

    sorry, i'm just using sql server 2000. are there any other ways?

    how about with stored procedure? is it advisable to use stored procedure
    with this problem?

    thanks.
    joe

  4. #4
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: how to select a record and delete from table afterwards?

    In 2000 there's no way that I know of - then you must select and delete in two different operations.

  5. #5
    Join Date
    Apr 2006
    Posts
    19

    Re: how to select a record and delete from table afterwards?

    oh i see.

    by the way, does it make a difference for the processing speed if i'll call select and delete in 2 separate sql statements or is it better to use single stored procedure( for select & delete) for this one?

  6. #6
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: how to select a record and delete from table afterwards?

    Well - with 1 stored procedure you'll only call the database once, and depending on how your data-access code layer is set up it would mean one less round trip to the database.

    So personally - I'd wrap it in a Stored Procedure.

  7. #7
    Join Date
    Apr 2006
    Posts
    19

    Re: how to select a record and delete from table afterwards?

    hi,

    thanks for the response.

    i'm still a newbie in stored procedure, is it ok if you can give me an example on how to create
    that kind of stored procedure?

    and also how to call it from visual c++ application and returns recordset?

    thank you very much,
    joe

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured