May 2, 2008 at 8:06 am
Write code in SQL that counts from 1 to 100. For each number evenly divisible by 3, substitute “BIZZ”. For each number evenly divisible by 5, substitute “BUZZ”, and lastly for each number evenly divisible by both 3 and 5 substitute “BIZZBUZZ”.
this was found on a site as a possible interview question
any other solutions out there
declare @x decimal(10,2)
select @x = 1
while @x < 101
begin
If @x / 3 = floor((@x / 3)) and @x / 5 = floor((@x / 5))
Print convert(varchar(10),convert(int,@x)) + ' - BIZZBUZZ'
Else If @x / 3 = floor((@x / 3))
Print convert(varchar(10),convert(int,@x)) + ' - BIZZ'
Else If @x / 5 = floor((@x / 5))
Print convert(varchar(10),convert(int,@x)) + ' - BUZZ'
Else
Print convert(int,@x)
select @x = @x + 1
end
May 2, 2008 at 8:25 am
Mark - I think the thread originated here, and got picked up elsewhere. The thread is still around - with some 200+ answers.
Take a look here:
http://www.sqlservercentral.com/Forums/Topic362081-217-1.aspx
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply