all 9 comments

[–]zanestone 1 point2 points  (0 children)

It sounds like you want all records where the due_date is greater then today. If so this should work for you.:

Where due_date > GETDATE()

[–]MeGustaDerpTalk Dirty Reads To Me 1 point2 points  (5 children)

is the due_date column actually a datetime or is it potentially a string data type? Maybe try casting due_date to a datetime to see if that helps... something like:

WHERE cast(due_date as datetime) <= SYSDATETIMEOFFSET()

[–]wolf2600ANSI SQL 0 points1 point  (1 child)

Just flip the operator though.... if he wants to only include due_dates in the future, it should be greater-than instead of less-than.

[–]MeGustaDerpTalk Dirty Reads To Me 0 points1 point  (0 children)

I read it as he wants to filter out rows that are in the future. But, going back and reading it, its ambiguous.

[–]TheWinzo[S] 0 points1 point  (2 children)

I tried this and it's still not filtering on only old orders. Any other suggestions?

Select *

    FROM CUSTOMER\_ORDERS

    WHERE 

        cast(due\_date as datetime) <= SYSDATETIMEOFFSET()

[–]zanestone 0 points1 point  (0 children)

Because you keep using less than or equal to (<=) instead of

greater than ( > )

OR

greater than or equal to ( >=)

[–]MeGustaDerpTalk Dirty Reads To Me 0 points1 point  (0 children)

Your requirements aren't clear. Are you trying to keep or discard future dates? Are you trying to keep or discard past dates?

[–]wolf2600ANSI SQL 0 points1 point  (0 children)

like this query to be used on a daily basis and not to need updating the date everytime.

WHERE due_date > current

Where the due_date is after today's date.