SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Syntax for dates
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sri99860
Starting Member

7 Posts

Posted - 12/11/2012 :  09:02:57  Show Profile  Reply with Quote
Hello,

I am new to SQL Server 2008. Need replacement functions for the below queries(sql)in sql server 2008.

1. trunc(sysdate)-1.0001
2. Trunc(sysdate - 3)
3. Trunc(sysdate, 'MM')
4. trunc(sysdate, 'DAY')
5. TO_YMINTERVAL('03-00')
6. TO_YMINTERVAL('00-01'))) +.99999
7. Trunc(last_day(Trunc(sysdate, 'MM')
8. to_char(Trunc(sysdate-1), 'D')
9. next_day(trunc(sysdate)-7.00001,'Saturday')
10.trunc(last_day(Trunc(sysdate, 'MM')
11.add_months(trunc(sysdate,'Q'),- 3)

Appreciate for your quick response.

Regards,
Sri.

sodeep
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 12/11/2012 :  09:14:10  Show Profile  Reply with Quote
use this for equivalent in SQL.

http://www.sqlines.com/oracle/functions/trunc_datetime
Go to Top of Page

sri99860
Starting Member

7 Posts

Posted - 12/12/2012 :  05:33:13  Show Profile  Reply with Quote
Thanks for your reply.

The link was provided had only trunc replacement functions.

Any one knows other functions.

Regards,
Sri.
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2210 Posts

Posted - 12/12/2012 :  05:47:13  Show Profile  Reply with Quote
to_char(Trunc(sysdate-1), 'D') --If you want day part from a date, DATEPART( D, dateField)
For data type conversions, see CONVERT and CAST functions
To add -3 months, DATEADD( MM, -3, DateFileld)

EDIT:
See 2.4.8 section in this link
http://docs.oracle.com/cd/E10405_01/doc/appdev.120/e10379/ss_oracle_compared.htm#i1038077


--
Chandu

Edited by - bandi on 12/12/2012 05:56:56
Go to Top of Page

sri99860
Starting Member

7 Posts

Posted - 12/13/2012 :  04:38:08  Show Profile  Reply with Quote
Thanks Bandi.

I am getting "Operand data type date is invalid for subtract operator." error if i subtract one query from the other. However if the query was running successfully if i split the query.

Select 'Previous 36 Months' as DateRange,
CONVERT(DATE,DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0)),120) - CONVERT(VARCHAR(10),DATEADD(m,-1+.99999,GETDATE()),120) as EndDate

Regards,
Sri.
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2210 Posts

Posted - 12/13/2012 :  04:47:49  Show Profile  Reply with Quote
In mssql, You can't subract two dates. refer DATEDIFF(),DATEADD() date functions...

--
Chandu

Edited by - bandi on 12/13/2012 04:48:47
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000