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

Group By concatenated field in cfquery

Guest
Jun 15, 2010 Jun 15, 2010

SELECT B_Model,B_Year, P_Brand, P_Pitch, count(P_Pitch)as Recordcount,
(P_Brand+' '+ P_Pitch)as Prop
FROM dbo.User_Record
WHERE B_Model = 'COUGAR FTD'
AND
B_Year = '2010'
GROUP BY Prop, P_Brand,P_Pitch,B_Model,B_Year
ORDER BY recordcount DESC

I can't seem to get this query to recognize Prop as a valid field for group by.  Any help would be appreciated.

P_Brand and P_Pitch are both nvarchar fields.

Thanks, Allen

TOPICS
Getting started
716
Translate
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 ,
Jun 15, 2010 Jun 15, 2010

IIRC you can't use alaises in the group by clause.

I've always had to do it this way.

SELECT B_Model,B_Year, P_Brand, P_Pitch, count(P_Pitch)as Recordcount,
(P_Brand+' '+ P_Pitch)as Prop
FROM dbo.User_Record
WHERE B_Model = 'COUGAR FTD'
AND
B_Year = '2010'

GROUP BY (P_Brand+' '+ P_Pitch), P_Brand,P_Pitch,B_Model,B_Year
ORDER BY recordcount DESC

Translate
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
Guest
Jun 15, 2010 Jun 15, 2010

Thanks, I haven't coded in a while, and just plane forgot about the alias.

I just fixed the form, and loaded the value directly to a Prop field.

Thnaks, for the quick help.

Allen

Message was edited by: DFR

Translate
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 ,
Jun 15, 2010 Jun 15, 2010
LATEST

Regarding grouping by aliases, that depends on the database.  At, least one, redbrick, lets you do it.

Translate
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