question

Rod avatar image
Rod asked

Why am I getting the error "Incorrect syntax near '<'."?

Very simple question here, but MAN am I stumped! Why does the following simple SQL SELECT statement yield the error message, "Incorrect syntax near ' t-sqloperator
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Mrs_Fatherjack avatar image
Mrs_Fatherjack answered
I'm confused, should this be in the where clause? Currently your script isn't actually doing anything, if you put that in the where clause, as below, it works fine. SELECT ABS(DATEDIFF(DAY, '2009-10-27 15:10:36.757', GETDATE())) WHERE ABS(DATEDIFF(DAY, '2009-10-27 15:10:36.757', GETDATE()))
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Ah, THAT'S what I was misunderstanding. Thank you.
0 Likes 0 ·
Kev Riley avatar image
Kev Riley answered
Evaluating an expression to True or False, will not result to that being returned as a value. It is a syntax error as you are not specifying what to select
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image
ThomasRushton answered
What you could do, though, if you want to select based on this sort of thing is SELECT CASE WHEN ABS(DATEDIFF(DAY, '2009-10-27 15:10:36.757', GETDATE()))
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.