Skip to content
Advertisement

Get date today, if no data – get data from yesterday (dynamic)

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)

Advertisement

Answer

try this If column sku.ohpost type is date

where  sku.ohpost = ( select max(sku.ohpost ) from mytable)
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement