BusinessObjects Board

Syntax for Previous Month name from Getdate in SQL syntax

Please provide the Syntax for getting the ‘Previous Month Name’ from GETDATE(). This is required for Predefined filter. Envrionment is SQL Server 2005 and BOXI 3.1.


chaithu1983 (BOB member since 2009-05-19)

This FAQ should get you started:-

https://bobj-board.org/t/152613

You will then have to adapt the code to return the actual month name.


Mak 1 :uk: (BOB member since 2005-01-06)

datename(mm,dateadd(m,-1,getdate()))

Thanks Mark P. it is perfect.


chaithu1983 (BOB member since 2009-05-19)


DECLARE @PreviousMonthStart DATETIME
DECLARE @PreviousMonthEnd DATETIME
 
SET @PreviousMonthStart = DATEADD(m,DATEDIFF(m,0,GETDATE())-1,0)
SET @PreviousMonthEnd = DATEADD(ms,-2,DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0))

PRINT @PreviousMonthStart
PRINT @PreviousMonthEnd	
		

SELECT * FROM MyTable
WHERE MyDate >= @PreviousMonthStart
AND MyDate  < @PreviousMonthEnd

hrothenb (BOB member since 2012-08-24)

How do you think DECLARE, SET and PRINT will work in universe designer? :crazy_face:

Obviously forgetting that you’re replying to a six-year old thread!