Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Printed, while loop
- declare @str varchar(30), @i int = 0, @max int = 100;
- while @i <= 100
- begin
- if @i % 3 = 0
- set @str += 'Fizz'
- if @i % 5 = 0
- set @str += 'Buzz'
- if len(@str) !> 0
- set @str = convert(varchar(10), @i)
- print @str
- set @str = ''
- set @i +=1
- end
- go
- -- Result set
- ;with onehundred as (
- select top 100 row_number() over(partition by t.schema_id order by t.schema_id) as i
- from sys.types t
- join sys.types c
- on t.schema_id = c.schema_id
- )
- select
- case
- when i % 3 = 0 and i % 5 = 0 then 'FizzBuzz'
- when i % 3 = 0 then 'Fizz'
- when i % 5 = 0 then 'Buzz'
- else convert(varchar(10),i)
- end as FizzBuzz
- from onehundred
- order by i
- go
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement