Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Both of these statements work, but is there someway to combine them. Statement 1 is the count of plays - statement 2 is a count of plays where a field length is less than 10 characters long.-- count of playsselect cast([gamedate]as varchar(6))+' '+homeclubcode+' vs '+visitorclubcode, count(*) from videodirectorreport where gamedate >'07/01/2010' group by gamedate,homeclubcode, visitorclubcode order by gamedate-- number of plays without participation informationselect cast([gamedate]as varchar(6))+' '+homeclubcode+' vs '+visitorclubcode, count(*) from videodirectorreport where len(homeplayers)<'10' and gamedate >'07/01/2010' group by gamedate,homeclubcode, visitorclubcode order by gamedate
malpashaa
Constraint Violating Yak Guru
264 Posts
Posted - 2011-01-02 : 21:16:25
You can use CASE like this:
SELECT CAST(gamedate AS VARCHAR(6)) + ' ' + homeclubcode + ' vs ' + visitorclubcode, COUNT(*) AS count_of_plays, COUNT(CASE WHEN LEN(homeplayers) < '10' THEN 1 ELSE NULL END) AS number_of_plays_without_participation_information FROM videodirectorreport WHERE gamedate >'07/01/2010' GROUP BY gamedate, homeclubcode, visitorclubcodeORDER BY gamedate;