sql - Is there a way to set variables in a Select statement that can be used in the same statements WHERE clause? -
i'm looking way set variable in select statement can later used in where
clause.
here example:
select datediff(d,time_stamp,getdate()) var1 report var1 = 5
i noticed order var1
clause, works fine, when try use in statement doesn't work fine, gives error on var1
column.
this doesn't work either because doesn't return rows.
declare @var1 int select @var1 = datediff(d,time_stamp,getdate()) report @var1 = 5
if make sense you, can tell me in case don't have write redundant code this...
select datediff(d,time_stamp,getdate()) report datediff(d,time_stamp,getdate()) = 5
?
are looking this?
with qry ( select r.*, datediff(d,time_stamp,getdate()) diff report r ) select * qry diff > 1
Comments
Post a Comment