Thursday, 18 June 2009

How to Add Two And OR Conditions in the SQL Query

How to Add Two And OR Conditions in the SQL Query:

Create View v_currentreport
as
select [Date], [Revenue]from V_DataCollection(nolock)
where
(
((DATEPART(hh, getdate()) < 1) AND convert(varchar, date, 103) = convert(varchar,getdate()-1,103)) -- This condition will get data of the previous day if the present time is between 00 AM (ie, 12 AM) and 01 AM
OR
((DATEPART(hh, getdate()) >= 1) AND convert(varchar, date, 103) = convert(varchar,getdate(),103)) -- -- This condition will get data of the same day if the present time is between 01 AM (ie, 01 AM) and 29:59:59 PM
)

No comments:

Post a Comment