difficult "case when" and datediff sql query

28 Views Asked by At

I am trying to make this query work:

(case 
when R.DateofRepairInvoice is not null and [Last Repairs Rcvd] is null 
        then isnull(convert(varchar,(DATEDIFF((Case when Format(R.DateofRepairInvoice, 'dd') <= '24' 
                then EOMONTH ( R.DateofRepairInvoice ,0 ) 
                else DATEFROMPARTS(YEAR(DATEADD(M,1,R.DateofRepairInvoice))
                    ,MONTH(DATEADD(M,1,R.DateofRepairInvoice)
                    ,15))), getdate())),103),'') end) as [Repair Cash Days]

Basically when the condition is met, then calculate the date difference between a case when query and today's date. I just keep getting red squiggly lines:

Screenshot

No matter where I add or remove brackets and/or commas there seems to be something missing. Can anyone point me in the right direction as to how to correct this query, please?

0

There are 0 best solutions below