Home > OS >  Get date today, if no data - get data from yesterday (dynamic)
Get date today, if no data - get data from yesterday (dynamic)

Time:11-18

I have such an issue. I have a report that is built around today's date. We see data only from today. On Hand units from today.

However, we have many import issues and sometimes import fails and there is no data in this report. I was wondering if there may be a way to make it dynamic like to use MAX function with getdate() or anything similar. I always want to see data from today, however if there is no data available for today I would like to see the data from yesterday. If not from yesterday from a day before yesterday.

I need to change the date logic to just pull the data for the max date.

Does someone know how it can be done?

where  sku.ohpost = cast(getdate()as date)

CodePudding user response:

try this If column sku.ohpost type is date

where  sku.ohpost = ( select max(sku.ohpost ) from mytable)
  • Related