Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have table with 3 columns.1st start_time, 2nd end_time,3rd units
when I write a query i use alias for a column but I am unable to use it afterward.
select start_time,end_time,units,datediff(minute,starttime,endtime) as minutes,(minutes/units) as rate from tblpunch

What I have tried:

i have tried the above query but it is not working
Posted
Updated 4-Jan-22 23:49pm
v2
Comments
CHill60 5-Jan-22 5:38am    
What are the three column names on your table - you are listing lots of names here and it is not clear which are aliases and which are columns
Member 15084650 5-Jan-22 5:42am    
i have 3 coloums 1 start_time ,2 end_time ,3 units.

1 solution

You can't refer to aliases within the same select. Either use a Common Table Expression, a Sub-Query, Temporary table or Table Variable, or simply repeat the calculation.
SQL
select start_time,end_time,units,datediff(minute,start_time,end_time) as minutes,(datediff(minute,start_time,end_time)/units) as rate from tblpunch
 
Share this answer
 
Comments
Member 15084650 5-Jan-22 6:01am    
THANK YOU

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