I want to see the number of sales each salesperson makes in a month for a year and if they make no sales in any month they are dropped from the list. I have a while loop that I thought might do this but it errors. Anyone
know how to fix?
declare @month INT SELECT @month = 0 WHILE (SELECT @month) < 12 BEGIN set @month = @month + 1 IF (SELECT COUNT(sale) FROM sales WHERE datepart(YYYY,datesale ) = DATEPART (YYYY, getdate()) aND(DATEPART(mm,datesale) = @month AND salespersonid = 4)> 0 CONTINUE ELSE BREAK
know how to fix?