Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 deleting data from complex SQL statement

Author  Topic 

qutesanju
Posting Yak Master

193 Posts

Posted - 2009-12-15 : 02:19:41
how can I form a delete statement form this select statement
-----------------------------
1.
select * from
SAP_ORDER_COST LEFT JOIN KC_SAP_ORDER
ON SAP_ORDER_COST.SAP_ORDER_COST_ORDER_NUMBE_ = SAP_ORDER.SAP_ORDER_ORDER_NUMBE_CHR
Where SAP_ORDER_COST.SAP_ORDER_COST_ORDER_NUMBE_ <> SAP_ORDER.SAP_ORDER_ORDER_NUMBE_CHR
2.

Declare @LastRunDate as Dateime
set @LastRunDate='31-Dec-2008'

select *
from SAP_NOTIFICATION LEFT JOIN SAP_ORDER
ON SAP_NOTIFICATION.SAP_NOTIFICATION_ORDER_NUMB = SAP_ORDER.SAP_ORDER_ORDER_NUMBE_CHR
Where
(SAP_NOTIFICATION.SAP_NOTIFICATION_ORDER_NUMB IS NOT NULL AND SAP_ORDER.SAP_ORDER_ORDER_NUMBE_CHR IS NULL)
OR
(SAP_NOTIFICATION.SAP_NOTIFICATION_COMPL_DATE <= @LastRunDate AND SAP_NOTIFICATION.SAP_NOTIFICATION_ORDER_NUMB IS NULL)

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2009-12-15 : 05:37:31
Use...
delete TABLE_NAME
...rather than...
select *


Ryan Randall - Yak of all trades
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page
   

- Advertisement -