Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

while loop?

$
0
0
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
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?

Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>