Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple query

Status
Not open for further replies.

Naoise

Programmer
Dec 23, 2004
318
IE
If I were to do something like

select datediff(hour,myfieldtime,getdate()) as 'TimeDiff'
where 'TimeDiff' > 24

I would get an error

Syntax error converting the varchar value 'TimeDiff' to a column of data type int.

as it does not see TimeDiff as a field. How would I best express the above?
 
Code:
select datediff(hour,myfieldtime,getdate()) as TimeDiff
  from daTable
 where datediff(hour,myfieldtime,getdate()) > 24


r937.com | rudy.ca
 
Cheers, I thought there was going to be some ansi fu way of doing it!
 
perhaps an inline view (a.k.a. derived table) will be useful
Code:
select TimeDiff
  from (
       select datediff(hour,myfieldtime,getdate()) 
                  as TimeDiff
         from daTable
       ) as d  
 where TimeDiff > 24
:)


r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top