D
D
Dmitry Mityaev2019-09-30 09:07:24
Transact SQL
Dmitry Mityaev, 2019-09-30 09:07:24

What is wrong with the NOT IN expression?

What is wrong with the NOT IN expression?

Request

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') )


Mistake

5d919b918f891174844663.jpeg
5d919b981ee42273387299.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2019-09-30
@tsklab

In NOT INyou can use either constants or a subquery. And you are using a value from a table.
For two values ​​and <>enough.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question