Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. -- Printed, while loop
  2. declare @str varchar(30), @i int = 0, @max int = 100;
  3.  
  4. while @i <= 100
  5. begin
  6. if @i % 3 = 0
  7. set @str += 'Fizz'
  8. if @i % 5 = 0
  9. set @str += 'Buzz'
  10. if len(@str) !> 0
  11. set @str = convert(varchar(10), @i)
  12.  
  13. print @str
  14. set @str = ''
  15. set @i +=1
  16. end
  17. go
  18.  
  19.  
  20. -- Result set
  21. ;with onehundred as (
  22. select top 100 row_number() over(partition by t.schema_id order by t.schema_id) as i
  23. from sys.types t
  24. join sys.types c
  25. on t.schema_id = c.schema_id
  26. )
  27.  
  28. select
  29. case
  30. when i % 3 = 0 and i % 5 = 0 then 'FizzBuzz'
  31. when i % 3 = 0 then 'Fizz'
  32. when i % 5 = 0 then 'Buzz'
  33. else convert(varchar(10),i)
  34. end as FizzBuzz
  35. from onehundred
  36. order by i
  37. go
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement