473,486 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

SELECTing from a DML statement

DB2 allows one to select from an insert, update, or delete, e.g.:

select * from old table (delete from x where y = 1);

--OR--

select * from new table (update x set y = 1 where z = 2);

--OR--

select * from final table (insert into x (c1) values (1));

Is there any equivalent in SQL Server?

Thanks and regards,

--Jeff
Jul 3 '08 #1
3 2441
On SQL Server 2008 you can use composable DML:

SELECT keycol, datacol
FROM (DELETE Foo
OUTPUT Deleted.keycol, Deleted.datacol
WHERE keycol = 1) AS T(keycol, datacol);

The key here is the OUTPUT clause that provides the data set.

HTH,

Plamen Ratchev
http://www.SQLStudio.com
Jul 3 '08 #2
Plamen Ratchev wrote:
On SQL Server 2008 you can use composable DML:

SELECT keycol, datacol
FROM (DELETE Foo
OUTPUT Deleted.keycol, Deleted.datacol
WHERE keycol = 1) AS T(keycol, datacol);

The key here is the OUTPUT clause that provides the data set.
Nice! Alway glad to see my stuff used. :-)

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Jul 4 '08 #3
To add on to Planen's response, you can also use the OUTPUT keyword in SQL
2005 or SQL 2008 to return DML results. For example:

DELETE dbo.Foo
OUTPUT deleted.keycol, deleted.datacol
WHERE keycol = 1;

This isn't as flexible as the composable DML introduced in SQL 2008 but I
believe it addresses your stated requirements. See the Books Online for
more information.

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

"jefftyzzer" <je********@sbcglobal.netwrote in message
news:8c**********************************@u12g2000 prd.googlegroups.com...
DB2 allows one to select from an insert, update, or delete, e.g.:

select * from old table (delete from x where y = 1);

--OR--

select * from new table (update x set y = 1 where z = 2);

--OR--

select * from final table (insert into x (c1) values (1));

Is there any equivalent in SQL Server?

Thanks and regards,

--Jeff
Jul 5 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2975
by: Alastair Cameron | last post by:
VB6, MSXML 3.2 installed: Q1. I am having a problem selecting nodes with XPATH expressions when an attribute values contain backslashes (\\) in as part of its value: For example the...
0
1153
by: Hijax | last post by:
Hi, What about posgtesql performace in selecting from million of records? I have a database with about 23 miilion of touples in single table. Data represents a analog signal values from...
1
1953
by: Kim | last post by:
Hello, I am selecting data from a text file with the following statement: "INSERT INTO SELECT * FROM " & sSource & " IN '' " & _ "'text;Database=" & sPath & ";FMT=Delimited;HDR=No' " & _...
7
1582
by: SHPsalm139 | last post by:
I'm working on a school application. I have a form where the user selects the marking period (1, 2, 3 or 4). That ties in to the "marking_period" field in a table. If the user indicates, for...
2
2581
by: movieking81 | last post by:
If someone could help me with this, that would be great. I need to select a number of records from an SQL table based on a date range, so I started with this select. <html> <code> resultssql =...
4
2084
by: darrel | last post by:
I have a DDL list along these lines: item value="1" text="a" item value="2" text="b" item value="3" text="c" item value="2" text="d" item value="2" text="e" item value="1" text="f" item...
5
2874
by: megahurtz | last post by:
I need to put together an SQL statement and I can't think of how to make it work properly. The scenario is that I have news items in a database that have a launch time and can optionally have an...
2
1374
by: megahurtz | last post by:
I need to put together an SQL statement and I can't think of how to make it work properly. The scenario is that I have news items in a database that have a launch time and can optionally have an...
2
2760
by: sdanda | last post by:
Hi , Do you have any idea how to improve my java class performance while selecting and inserting data into DB using JDBC Connectivity ......... This has to work for more than 8,00,000...
1
1265
by: Cyprus106 | last post by:
I need a sql statement that doesn't select any record that has already been selected with the same data in a field. In other words, if I had these 3 records in the form of NAME, ID, and PHONE ...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7330
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5434
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4865
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3070
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.