Select
ACCOUNT_ID,
PAYMENT_DATE,
coalesce(DATEFORMAT(pay.PAYMENT_DATE,'mm.yyyy'),'nl'),
---DATEADD( MONTH, -1, DATEFORMAT(pay.PAYMENT_DATE,'mm.yyyy') )
DATEADD( MONTH, -1, pay.PAYMENT_DATE ),
----DATEFORMAT((DATEADD( MONTH, -1, pay.PAYMENT_DATE )), 'mm.yyyy') )
DATEFORMAT(DATEADD( MONTH, -1, pay.PAYMENT_DATE ),'mm.yyyy') df
---DATEADD( MONTH, -1, (pay.PAYMENT_DATE),'mm.yyyy'),
---CAST ( DATEADD( MONTH, -1, (pay.PAYMENT_DATE) ),'mm.yyyy') AS VARCHAR(9)] )
---CONVERT ( CHAR( 20 ), pay.PAYMENT_DATE, 365)
FROM
(select pay.ACCOUNT_ID, MAX(pay.PAYMENT_DATE)PAYMENT_DATE
from spss.PAYMENTS pay, ----KOLLECTO.PAYMENTS
spss.PAYMENTS_DOC pd
where pay.PAYMENT_DOC_ID=pd.PAYMENT_DOC_ID
and pd.PAYMENT_DOC_TYPE='NORMAL'
and pay.fnc_amount>=500
GROUP BY pay.ACCOUNT_ID) pay
WHERE
---coalesce(DATEFORMAT(pay.PAYMENT_DATE,'mm.yyyy'),'nl') not in ( DATEFORMAT(GETDATE(),'mm.yyyy'), DATEFORMAT(DATEADD( MONTH, -1, (pay.PAYMENT_DATE) ),'mm.yyyy') )
coalesce(DATEFORMAT(pay.PAYMENT_DATE,'mm.yyyy'),'nl') not in ( DATEFORMAT(GETDATE(),'mm.yyyy'), DATEFORMAT(DATEADD( MONTH, -1, (pay.PAYMENT_DATE) ),'mm.yyyy') )