SQL SERVER - Using DATEDIFF with subquery column -


i have query looks like:

select     col1     ,...     ,col3     ,(select col3 table <clause>) minpicktime     ,(select col3 table <clause>) maxpicktime     ,datediff(d, minpicktime, maxpicktime) table 

however datediff line not alias columns.

in short, how give datediff alias column derived subquery?

use derived tables concept access alias name.

select  col1     ,...     ,col3,      minpicktime,      maxpicktime , datediff(d, minpicktime, maxpicktime) ( select     col1     ,...     ,col3     ,(select col3 table <clause>) minpicktime     ,(select col3 table <clause>) maxpicktime  table )z 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -