I want to run a SELECT statement and I want execute a DELETE statement for the same row and the read result be respond by the SQL Server.
+1
A:
WITH cte AS (
SELECT *
FROM <mytable>
WHERE key = <mykey>)
DELETE cte
OUTPUT deleted.*;
There are many ways to skin this cat. I often preffer the one posted because is very readable. It clearly separates the SELECT into its own query expression, allowing for easily created complex queries. It deletes exactly the query result. It outputs the deleted rows.
The following is also perfectly valid and easier for simple WHERE clauses:
DELETE <mytable>
OUTPUT deleted.*
WHERE key = <mykey>;
Remus Rusanu
2009-09-08 16:46:16
thanks buddy,this is useful for me but can u tell me a little bit more . i am telling you what i want to do.i am working on a chat application so i want to read the new chat and in the same instance the chat that is read should be deleted so that this not be repeated. so please tell me.
Abhisheks.net
2009-09-09 04:43:46