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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 convert PLSQL TO TSQL

Author  Topic 

Blessed1978
Yak Posting Veteran

97 Posts

Posted - 2014-06-20 : 07:07:49
I need to convert the below PLSQL code into TSQL
Please advise

delete from employees where transaction_id in(

select transaction_id from employees sf, calendar_chart cd

where cd.calendar_chart = sf.date_id

and cd.calendar_date > '05-JAN-2012'

and trim(trade_type) = 'C'

and trim(trans_cd)||'~'||trim(trans_suffix) <> '001~021'

and exists (select 1 from department_history where trim(order_no) = trim(sf.order_no) and trim(trans_cd)||'~'||trim(trans_suffix) = '001~021' and trim(trade_type) = 'A'));

adsingh82
Starting Member

20 Posts

Posted - 2014-06-20 : 07:47:03
please find the converted code below


DELETE FROM DBO.employees
WHERE transaction_id IN
(
SELECT transaction_id
FROM employees sf, calendar_chart cd
WHERE cd.calendar_chart = sf.date_id
AND cd.calendar_date > CONVERT(DATETIME, '05-JAN-2012')
AND RTRIM(LTRIM(trade_type)) = 'C'
AND RTRIM(LTRIM(trans_cd))+ '~'+ RTRIM(LTRIM(trans_suffix)) <> '001~021'
AND EXISTS (
SELECT 1 FROM department_history
WHERE RTRIM(LTRIM(order_no)) = RTRIM(LTRIM(sf.order_no))
AND RTRIM(LTRIM(trans_cd)) + '~' + RTRIM(LTRIM(trans_suffix)) = '001~021'
AND RTRIM(LTRIM(trade_type)) = 'A'
)
);


Regards,
Alwyn.M
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-06-21 : 05:25:26
Please pass date values in unambiguos formats as that will get correctly interpreted regardless of language and regional settings

pass value as 20120105

http://visakhm.blogspot.in/2011/12/why-iso-format-is-recommended-while.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -