tags:

views:

109

answers:

2

I am working in SQL 2005 (I think), SQL Query Analyzer Version SQL 8.00.760.

I would like to write a query that returns a count into a Crystal Report from a table only if the due date exceeds 14 days based on the end date in the report search. Based on my very limited understanding of SQL, I have come up with the following, which has proven to be wrong. Please help me redo or refine this statement.

Select
   T.NextDueDate
From
   Task_ConditionAssessment T
  begin
     IF DATEDIFF(dd,T.NextDueDate,@enddate)>14
     Count(*)
  end

Again, this is not correct, but I am unsure what should be done differently....the error returned was Line 5: Incorrect syntax near 'count'.

Thanks in advance.

+2  A: 

I think you want something like this:

SELECT COUNT(*) 
FROM Task_ConditionAssessment T 
WHERE DATEDIFF(dd,T.NextDueDate,@enddate) > 14
mwigdahl
Beat me to it... ;-)
gbn
Sweet..... Thank you!
Erin Karschnik
No problem, glad it works for you!
mwigdahl
A: 

Try it:

SELECT COUNT(*) 
FROM Task_ConditionAssessment 
WHERE DATEADD(dd, 21, @enddate) > NextDueDate

This gives you how many tasks are after 14 days from @enddate.

eKek0