April 28, 2011 at 5:57 pm
I have a table1 with it's fields all stored as text
Name lastname Age
----- -------- ----
John Doe 23
Mary Doe 34
James Doe 27
Jerry Doe 29
My select statement needs to compare the age of an employee to a number and if it
is greater than 25 to return 1 otherwise a blank.
I am getting an error running the following query "Incorrect Syntax near '>' ",
what am I doing wrong?
Thanks in advance
SELECT NAME, LASTNAME,
CASE AGE
WHEN (CAST(AGE as int) > 25 then 1
ELSE ''
END AS QUALIFIED
FROM TABLE1
April 28, 2011 at 6:13 pm
No need to CAST.
SELECT
NAME, LASTNAME,
CASE WHEN AGE > 25 THEN '1' ELSE '' END AS QUALIFIED
FROM
TABLE1
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgApril 29, 2011 at 8:27 am
But to address the syntax error, you have an open parentheses with no matching close parentheses.
April 29, 2011 at 9:10 am
Jason Selburg (4/28/2011)
No need to CAST.
SELECT
NAME, LASTNAME,
CASE WHEN AGE > 25 THEN '1' ELSE '' END AS QUALIFIED
FROM
TABLE1
Just a bit more information, if you want to review/save a chart of implicit conversions, follow the link and scroll down to the middle of the displayed page.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply