|
Posted by Ray via SQLMonster.com on 07/20/05 21:08
Hi Stu,
Thank you very very much ..... it was a great help.
Best regards,
Stu wrote:
>If you don't have a calendar table (which can be very helpful for
>situations like this), you can do it on-the-fly using SQL Server like
>so:
>
>SELECT DATEADD(m, -1, FirstOfCurrentMonth) as FirstOfPreviousMonth,
> DATEADD(d, -1, FirstOfCurrentMonth) as LastOfPreviousMonth
>FROM (SELECT CONVERT(smalldatetime,DATENAME(m, GetDate())
> + ' 1,' + DATENAME(yyyy, GETDATE())) as FirstOfCurrentMonth) a
>
>Of course, you'll want to do the formatting on the client side.
>
>HTH,
>Stu
--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-general/200507/1
Navigation:
[Reply to this message]
|