I’m trying the following SQL query:
select (execution_end_timestamp - execution_queued_timestamp) as totalTime, execution_queued_timestamp from exec_queue
where execution_name like '%Generate%'
and execution_queued_timestamp > '2012-10-04 20:00:00.000'
having totalTime < '1900-01-01 00:00:06.000'
I’ve tried using the totalTime in the where and having clause and in both cases it doesn’t work. I also tried datediff hoping that might work, but it had identical results.
Is there a trick where you can use a computed field in a where or having clause? Googling around hasn’t turned up anything except in cases where an aggregating function is used.
No, alias is not allowed on
WHEREclause, try,Reason why
ALIASdoesn’t work onWHEREandHAVINGclause,from clauseis formed.where clauseis then evaluated to eliminate rows that do not satisfy the search_condition.group by clause.having clause are eliminated.select clausetarget list are evaluated.distinct keywordin present in the select clause, duplicate rows are now eliminated.unionis taken after each sub-select is evaluated.order by clause.