• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Query Problem

Explorer ,
Jul 01, 2009 Jul 01, 2009

Copy link to clipboard

Copied

I have been looking at code entirely to long and I keep getting a sql syntax error with the below code. Just wondering if anyone can see anything right off with the query before I go into more detail, I think I need some fresh eyes looking at it. This is being run against a MySQL server. TIA

select bcastreq.bcast_id, bcastreq.affiliate_id, bcastreq.subject, DATE_FORMAT(bcastreq.reqtimestamp, '%m/%d/%Y') as reqtimestamp, affiliate.affiliatename,  bcastreq.affiliatetype_id, count(editbcastreq.bcast_id) as editcount, editbcastreq.affiliatetype_id
from bcastreq
left join editbcastreq
on bcastreq.bcast_id = editbcastreq.bcast_id
left join affiliate
on bcastreq.affiliate_id = affiliate.affiliate_id
group by bcastreq.bcast_id
<cfif Arguments.filtercolumn NEQ "" AND Arguments.filter NEQ "">
where #Arguments.filtercolumn# like '#Arguments.filter#%'
</cfif>
<cfif Arguments.gridsortcolumn NEQ "">
order by #Arguments.gridsortcolumn# #Arguments.gridsortdirection#
</cfif>

TOPICS
Advanced techniques

Views

750

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 01, 2009 Jul 01, 2009

Copy link to clipboard

Copied

I'm not sure, can the group by clause come before the where clause like that.  IIRC there is a certain expected order to the SQL clauses.  I'm just not sure if this is required or just convention.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 01, 2009 Jul 01, 2009

Copy link to clipboard

Copied

Ian's observation is correct.  The where clause must precede the group by clause.

Also.

You are selecting 3 or 4 fields but only grouping by 1.

Is date_format a valid mysql function?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 02, 2009 Jul 02, 2009

Copy link to clipboard

Copied

Thanks all. The date_format has been working fine. I did not start  to have problems until I added the cfif statements to the query. I will try and give your suggestions a try today if I get a chance. Thanks again.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 02, 2009 Jul 02, 2009

Copy link to clipboard

Copied

LATEST

Thanks. Its always something simple. The location of the where clause was the problem. Much appreciated.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation