sql DateDiff help

erikTsomik
erikTsomik used Ask the Experts™
on
I need to show the record that is 24 hours priors of session start.

CASE WHEN isNULL(s.repost,0) = 1 
		THEN 
			DateDiff(hh,SU.sessionStart,GETDATE()) 
		ELSE 
			datediff(d, getdate(), SU.sessionStart) 
		END
 >= CASE WHEN isNULL(s.repost,0) = 1 
		THEN 
			24
		ELSE 
			3
		END 

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Database and Application Developer
Commented:
Select f1, f2
From (Select f1, f2,
CASE WHEN isNULL(s.repost,0) = 1 
		THEN 
			DateDiff(hh,SU.sessionStart,GETDATE()) 
		ELSE 
			datediff(d, getdate(), SU.sessionStart) 
		END As DateCriteria
From TableYouHave) As D (f1, f2, DateCriteria)
Where DateCriteria <=24

Open in new window

PortletPaulEE Topic Advisor
Most Valuable Expert 2014
Awarded 2013

Commented:
I'm sorry but I don't understand the question as the sql in the question make no sense from line 7 onward

Please remember that THE BEST WAY TO ASK  is to provide:

a. sample data
b. the expected result

If we understand the question easily you get an answer faster and you don't need to clarify the question for us.
awking00Information Technology Specialist

Commented:
select ...
where dateadd(d,1,SU.sessionStart) >= getdate()
Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
erikTsomik, do you still need help with this question?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial