Imagine this scenario, you required a script that would count to 50 and test each number along the way.
If the number was divisible by 2 it would need to print ‘DBA’, if it was divisible by 5 it would print ‘Fire’
If by both then ‘DBAFIRE’
This is a variation of this question.
DECLARE @counter INT SET @counter = 1 WHILE @counter < 51 BEGIN SELECT @counter, CASE WHEN @counter %2 =0 AND @counter %5 = 0 THEN 'DBAFire' WHEN @counter % 2 = 0 THEN 'DBA' WHEN @counter % 5 = 0 THEN 'Fire' ELSE '' END SET @counter = @counter+1 END