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
 Change Oracle To MS-SQL

Author  Topic 

sgreeny
Starting Member

2 Posts

Posted - 2009-10-09 : 01:40:36
How to convert the following oracle statement to MS-SQL
(1) select TO_DATE(MTH_NO||'-'||YR_NO,'MM-YYYY') FROM MyTable
(2) SELECT NVL2(CURR_TM_MTH,TO_DATE(CURR_TM_MTH,'MM-YYYY'),SYSDATE) FROM MyTable

PS Sample data: MTH_No = 2 (means feb)
YR_NO = 1998
CURR_TM_MTH = 02-1998 (means mm-yyyy)

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-09 : 01:52:48

Do you want pure date value or formatted value?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

sgreeny
Starting Member

2 Posts

Posted - 2009-10-09 : 02:17:09
Hi,

Can I have both format? Thanks
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-09 : 03:07:50

select DATEADD(month,month_no-1,dateadd(year,year_no-1900,0)) from your_table

Let the front end do format it like mm-yyyy

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -