473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Column Alias Issue

Hi All,

I have having a problem conducting an aggregated function off an alias column I create on the fly. I get an error saying SearchType is an invalid column name yet when I remove the Count and Group By commands the query results in a column with the name of SearchType.

SELECT
Count(RFQ_ID), "SearchType"=
CASE
WHEN SVC_COLO = 'Y' THEN 'Colocation'
WHEN SVC_BANDWIDTH = 'Y' THEN 'Bandwidth'
WHEN SVC_MANAGED = 'Y' THEN 'Managed'
WHEN SVC_VOICE = 'Y' THEN 'Voice'
WHEN SVC_DARK_FIBER = 'Y' THEN 'Dark Fiber'
WHEN SVC_BIZ_CONT = 'Y' THEN 'Business Continuity'
END
FROM
RFQ
Where ACTIVE = 'Y'
Group By "SearchType"
Dec 7 '06 #1
1 6849
almaz
168 Expert 100+
You cannot use column aliases in the GROUP BY clause. You can either copy/paste the whole CASE statement to the GROUP BY clause or use nested SELECT statements like this (it won't hurt the performance of the query):
Expand|Select|Wrap|Line Numbers
  1. SELECT Count(RFQ_ID), SearchType
  2. FROM
  3. (
  4.   SELECT Count(RFQ_ID), 
  5.   SearchType =
  6.   CASE 
  7.      ...
  8.      ...
  9.   END
  10.   FROM RFQ
  11.   Where ACTIVE = 'Y'
  12. ) Source
  13. Group By SearchType
Dec 7 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Gord | last post by:
Hello, Anybody know how to detect when a user drags between columns in a MSHFlexGrid when resizing column width? (Short of setting up a timer event that continuously monitors column width.)...
3
by: Andrew | last post by:
With command-line interface ( 3.23.37, UNIX Socket ) all is well with column aliasing. However, column aliases disappear in Excel, over ODBC, when there are multiple (joined) tables in the query. ...
10
by: GML | last post by:
I have a bound datagrid in C# based on an an SQL query. The results are displayed in a Sharepoint 2003 Webpart. I would like to add a new column based on the results of two columns in the...
4
by: John Fabiani | last post by:
From the 7.4 docs: A column can be referenced in the form correlation.columnname correlation is the name of a table (possibly qualified with a schema name),or an alias for a table defined by...
6
by: blue875 | last post by:
A tale of two queries: One query looks like this, and runs fine. We'll call this the "Customer1 query": SELECT Customer1 overall.*, IIf(IsNull(.),0,1) AS IsField, IIf(IsNull(.),0,1) AS...
6
by: Mike S | last post by:
Hi all, A (possibly dumb) question, but I've had no luck finding a definitive answer to it. Suppose I have two tables, Employees and Employers, which both have a column named "Id": Employees...
1
by: deepak | last post by:
Hi There, i have a requiremet ,where in i have a view which has some alias.so at runtime using an application i will get the info about the view using SP_HELP stored proc,but this only gives me...
12
by: sheppardpg | last post by:
I have a a query with a column that needs to have a data type of Memo, which I am able to achive with this function; Public Function MEMO() MEMO (COMMENTS) End Function I want to define the...
1
by: Slapo | last post by:
Hello everyone, I could use some help with this function I've created (see below) that runs flawlessly on PostgreSQL 8.3.6 on my development machine but ends with an error on the production server...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.