Reputation: 157
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.
Upvotes: 0
Views: 299
Reputation: 23299
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.
Upvotes: 0
Reputation: 16578
I think you want something like this:
SELECT COUNT(*)
FROM Task_ConditionAssessment T
WHERE DATEDIFF(dd,T.NextDueDate,@enddate) > 14
Upvotes: 2