Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax Error

Status
Not open for further replies.

renee35

MIS
Jan 30, 2007
199
Please help with the below error I am getting when testing this select statement:

Select
'Test' = Case when 1099flag = '1' then 0
else sum(isnull(checkamount,0)) end
from table2

Error: Line 2: Incorrect syntax near 'flag'.

Thanks a bunch!!

-T
 
Hi,

Hmm not sure what you're trying to do here... is it the following?

Code:
select 
 case when 1099flag = '1' then 0
 else sum(isnull(checkamount,0)) end as 'Test'
from table2
group by checkamount

Ryan
 
The column 1099flag does not conform to the rules for regular identifiers, square brackets are required e.g. [1099flag]


This will fix your first error but generate another: "Column 'table2.1099flag' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause."

You'll need a group by as shown by RyanEK to resolve this. Exactly how you should group depends on what you are trying to achieve.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top