Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Here is a table and it has suppose three column

ID Value1 Value2
1 100 50
2 80 40
3 30 30
4 50 40

Select ID, Value1, Value2, (Value1+Value2) as Value from table where Value>100

I want to write the above sql query but getting error
Msg 207, Level 16, State 1, Line 1
Invalid column name 'Value'
Posted
Comments
__TR__ 15-Nov-12 5:32am    
Try
Select ID, Value1, Value2, (Value1+Value2) as Value from table where (Value1+Value2)>100
sahabiswarup 15-Nov-12 6:00am    
thanks

value is a reserved keyword in SQL so you cannot use as is, try the following:
SQL
Select ID, Value1, Value2, (Value1+Value2) as [Value] from table where (Value1+Value2)> 100

to see list of reserved keywords, see the following MSDN article:
http://msdn.microsoft.com/en-us/library/aa238507(v=sql.80).aspx[^]
 
Share this answer
 
v2
Comments
Dylan Morley 15-Nov-12 6:07am    
While I agree that you should avoid reserved words, you cannot use a calculated field in a where clause, you must use the calculation.

The comment from __TR__ is correct.
Select ID, Value1, Value2, (Value1+Value2) as Value from table where (Value1+Value2)>100


value is only an alias you can't apply condition with it
 
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