We help IT Professionals succeed at work.
Get Started

sql count for a week

175 Views
Last Modified: 2015-03-31
I have a query where I am counting number of session per weekdays and this part works.

What the problem is when the date is passed I want to check the week and count the number of session in that week, instead I get the number of sessions for that day

Select WeekStart = convert(varchar(10),dateadd(week, datediff(week, 0, SU.sessionStart), 0),105),CountID = Count(S.sessionKey)

			FROM SessionUnit SU
			INNER JOIN Session S on S.sessionKey = SU.sessionkey
			INNER JOIN product P on p.productKey = S.productKey
			CROSS APPLY (
			    SELECT item AS SPLITLOCATIONKEY
			    from DelimitedSplit8K(S.locationKeyList, ',')
			)as ca
			INNER JOIN location AS L2 ON CA.SplitLocationKey = L2.LocationKey AND (L2.locationKey in (228,260))
			WHERE  su.sessionStart >= DateAdd(day,45,dateadd(day, datediff(day, 0, getdate()), 0))
			AND su.sessionStart <  DateAdd(day,91,dateadd(day, datediff(day, 0, getdate()), 0))
			AND datediff(day, 0, su.sessionStart) % 7 not in (5, 6)
			AND p.productKey = 2  and SU.instructorKey = 13879
			and convert(date,SU.sessionStart) = '2015-05-13'
			GROUP BY
			 dateadd(week, datediff(week, 0, SU.sessionStart), 0)
			 --HAVING COUNT(S.sessionKey) >= 9

Open in new window

Comment
Watch Question
EE Topic Advisor
CERTIFIED EXPERT
Most Valuable Expert 2014
Awarded 2013
Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
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
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