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
 date query

Author  Topic 

angela_g
Starting Member

17 Posts

Posted - 2014-05-22 : 06:58:23
Hi Can anyone help me? I have found a query which contains something I dont recognise, what is the query requesting?

>= ADD_MONTHS ( trunc(SYSDATE), -1)

Thank you in advance!

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2014-05-22 : 07:10:10
That isn't MS SQL Server

see here:
https://www.google.de/#q=ADD_MONTHS+(+trunc(SYSDATE)%2C+-1)


Too old to Rock'n'Roll too young to die.
Go to Top of Page

adsingh82
Starting Member

20 Posts

Posted - 2014-05-22 : 09:46:11
sysdate will produce the the current datetime and trunc will extract only the date part add_months subtracting one month from the current date

So this condition will result last one month data

Regards,
Alwyn.M
Go to Top of Page

GouravSaxena1987
Starting Member

23 Posts

Posted - 2014-05-22 : 12:55:45
Hello,
It will give you exactly one month previous date without any Hours,Minutes,Second values.
i.e.
If today date is - 22/05/2014:00:00:00

ADD_MONTHS ( trunc(SYSDATE), -1) will give : 22/04/2014

for reference please check:

http://www.techonthenet.com/oracle/functions/trunc_date.php

http://w3mentor.com/learn/procedural-language-structured-query-language/date-functions/date-functions-%E2%80%93-add_months/

Regards,
Gourav Saxena
Data Warehouse Counsultant
GouravSaxena1987@gmail.com
Go to Top of Page
   

- Advertisement -