I have written a query below, but cannot get sum to work, as it keeps giving me the wrong syntax, any ideas?
SELECT company.companyname, SUM(CASE WHEN datediff([d], cssdata.received, getdate()) < 30) as Less
FROM contract INNER JOIN
job ON contract.contractid = job.contractid INNER JOIN
cssdata ON job.jobid = cssdata.jobid INNER JOIN
allocation ON job.jobid = allocation.jobid INNER JOIN
vw_job_lastliveallocation ON allocation.allocationid = vw_job_lastliveallocation.lastallocation INNER JOIN
company ON allocation.companyid = company.companyid