Skip to content
Advertisement

Unable to pull data for todays date (where statements worked on other tables)

I am trying to pull data for today’s date in the timestamp column only. The ‘where’ statement I am using worked for my other table, but this is still pulling old data. I have been trying a bunch of other methods but I think they may not be working because of the timestamp data and not just the date.

select column1,
       tf.order_number,
       column3,
       timestamp_est,
       column5 as station
from wms.transition_fact tf
join order_dim od
on od.order_number = tf.order_number
where timestamp_est <= GETDATE()
and to_state in ('picking', 'picked', 'pouching', 'pouch_printing_configured', 'checking', 'checked', 'packing', 'packed')
and associate_name is not null
order by 1, 4 asc

Advertisement

Answer

Use this for your where clause:

where timestamp_est >= current_date and timestamp_est < (current_date + 1)

or shorter and clearer (but defeats an index on timestamp_est if any):

where timestamp_est::date = current_date
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement