Click here to Skip to main content
15,889,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi friend

why is this query wrong??

SQL
SELECT [Code],sum([Value]) as COL
  FROM [Stuff] where COL=250 GROUP BY [Code]


please guide me
Posted

You can not be using an alias as an element in the where clause. Possibly you may do the following
Select code, sum(value) as col
  from table
 having sum(value) = 250
 group by code
 
Share this answer
 
Column naming action perform after filtering the record. So when process try to execute COL=25 filter, it do not find any column with the name COL.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900