October 16, 2001 at 11:51 pm
I am facing a problem while calculating a field from an aliased field. The err that it gives me is: Invalid Column name
This is my code:
select
case EmployeesVestingSchedule.BasedOn
when 'P' then Portion
when 'T' then 0
end 'PerformanceBased_PerCent' ,
PerformanceBased_PerCent * Employee_Options.NoOfOptions/100as PerformanceBased_Numbers, ---- this gives an error ----
Employee_Options.NoOfOptions
from
EmployeesVestingSchedule , employee_options
Paras Shah
Evision Technologies
Mumbai, India
Paras Shah
Evision Technologies
Mumbai, India
October 18, 2001 at 11:50 am
This is because the 'PerformanceBased_PerCent' isn't yet available. The aliased field can't be used by your expression. You'll find that the aliased column is also unavailable in the WHERE, GROUP BY, or HAVING clauses of a SELECT statement as well. They are available in the ORDER BY clause. You may have to go to a subquery.
K. Brian Kelley
http://www.sqlservercentral.com/columnists/bkelley/
K. Brian Kelley
@kbriankelley
October 18, 2001 at 12:58 pm
December 8, 2002 at 5:55 pm
You might also considering storing this value as a denormalized column on your table. You can add a CHECK constraint to enforce your business rule. Since you're trying to influence the output of SQL with this value, it's a good candidate for an actual field instead of one generated through the query.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy