Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Creating a daily count using datediff and a month date range SQL SSRS

Avatar of BofADev
BofADev asked on
Microsoft SQL Server 2005
3 Comments1 Solution535 ViewsLast Modified:
Ultimately I need to create a report that looks something like this.
       Fixed Calls (# of calls where customer did not call back in 7 days from date)
2/1   20,000
2/2   18,000
2/3   17,500
2/4   15,000
2/5   21,123

Below you'll see my first attempt at getting this to work (and I think i have a way to go)

I have two things hopefully you can help me figure out.
1.)  Because I am joining on the Loan#, it's creating matches for every possible combination of each instance of the loan number.
2.)  What is the easiest way to get it to count the results on a daily basis, with the least amount of code.   Using the sample above i need it to read on 2/1/2009 there were 20,000 calls where over the course of the following 7 days, the loan number did not repeat again.  And continue that for the selected date range.

Loan = Loan#
LoggedBy = CSR talked to
LogDate = Date/time of call
UID=autonumber key
DECLARE @FromDate datetime
DECLARE @ToDate datetime
 
SET @FromDate='02/01/2009'
SET @ToDate='02/22/2009'
 
--Temp Table 1
DECLARE @DistinctCalls table (Loan varchar(10),LoggedBy varchar(7), LogDate datetime,FirstUID int)
insert @DistinctCalls 
SELECT Account_Num, [User_Id], LogDate=convert(varchar(10),date_time,101), FirstUID=min(UID)
FROM msp_comments
WHERE not_on_system='false' and systemnote='false'
and date_time>=@FromDate
and date_time <@ToDate
GROUP BY Account_Num, [User_Id],convert(varchar(10),date_time,101)
 
--Create 2nd temp table
DECLARE @DistinctCalls2 table (Loan varchar(10),LoggedBy varchar(7), LogDate datetime,FirstUID int) 
insert @DistinctCalls2 
SELECT Account_Num, [User_Id],LogDate=convert(varchar(10),date_time,101), FirstUID=min(UID)
FROM msp_comments
WHERE not_on_system='false' and systemnote='false'
and date_time>=@FromDate
and date_time <@ToDate
GROUP BY Account_Num, [User_Id],convert(varchar(10),date_time,101)
 
 
 
Select DISTINCT *,DateDiff(Day,a.LogDate,b.LogDate) AS Diff From @DistinctCalls a
Join (Select * From @DistinctCalls2) b on a.Loan = b.Loan
Where a.Loan = b.Loan and DateDiff(Day,a.LogDate,b.LogDate) < '7' and DateDiff(Day,a.LogDate,b.LogDate) <> '0'
ASKER CERTIFIED SOLUTION
Avatar of Mark Wills
Mark WillsFlag of Australia imageTopic Advisor
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answers