I happened to have a UDF in my test box that returns a set of numbers, so it was very easy for me to put this together:
The UDF is something I found on Mr Steve Kass's home page. In turn, he gives credit to Mr Itzik Ben-Gan.
create function Numbers( @from as bigint, @to as bigint) returns table with schemabinding as return with t0(n) as ( select 1 union all select 1  , t1(n) as ( select 1 from t0 as a, t0 as b  , t2(n) as ( select 1 from t1 as a, t1 as b  , t3(n) as ( select 1 from t2 as a, t2 as b  , t4(n) as ( select 1 from t3 as a, t3 as b  , t5(n) as ( select 1 from t4 as a, t4 as b  , Numbers(n) as ( select row_number() over (order by n) as n from t5   select @from + n - 1 as n from Numbers where n <= @to - @from + 1
Try it also with a million numbers. It is pretty fast!
Deadline missed, budget exceeded, client unhappy.
The problem was simple, the solution was not.
Ok, fed up reading the thread. I would have failed all the interviewers just simplely in comparing the following two code pieces:
--====== A ========
Case when @i % 3 = 0 and @i % 5 = 0 then 'BizzBuzz'
when @i % 3 = 0 then 'Bizz'when @i % 5 = 0 then 'Buzz'
when @i % 3 = 0 then 'Bizz'
when @i % 5 = 0 then 'Buzz'
--====== B ========
Case when @i % 5 = 0
case when @i % 3 = 0 then 'BizzBuzz' else 'Buzz' endwhen @i % 3 = 0 then 'Bizz'else Str(@i)
case when @i % 3 = 0 then 'BizzBuzz' else 'Buzz' end
The method B will save half of the modular calculation!
Heh... you read into it, ol' friend... no where in the post does there say anything about a time limit.
[Edit] Ok, I see where you came up with the 2 minute limit... wasn't in Grant's article but in one of the links provided...
If there were a 2 minute time limit for such a thing and it was during an interview, then yes... skip the comments 'cause that's not what they're looking for, but consider finding a job somewhere else because they've just set the stage for how they're gonna operate all the time.
So far as the total number being limited by some business logic... how many times has that happened to you only to have that business logic change?
I'll say it again, write performance enabled, scalable, documented code even for the simplest things... unless you really enjoy treading water
Heh... looking at it the wrong way...
Original budget/deadline was wrong because you didn't bid right... Client necessarily changes scale... wants to know why idiots wrote code that wasn't scalable... all future contracts lost because client thinks people who don't have their best interest at heart wrote the code.
And, wanna tell be why the following would take more than 2 minutes? It's still documented , scalable, nasty fast, and it still uses setbased thinking... customer happy, inteviewer happy, boss happy, and my peers don't get the work because I had the for-thought to write code anticipating a change...
--===== Limit the number of rows to be built SET ROWCOUNT 1000000
--===== Create and populate the table on the fly SELECT IDENTITY(INT,1,1) AS RowNum, CAST(NULL AS VARCHAR(10)) AS DesiredResult INTO #Nums FROM Master.dbo.SysColumns sc1 WITH (NOLOCK), Master.dbo.SysColumns sc2 WITH (NOLOCK)
--===== Restore the number of rows to return to normal -- Note: Can replace with TOP @variable in SQL 2k5 SET ROWCOUNT 0
--===== Produce the desired results according to the -- requirements SELECT CASE WHEN RowNum % 15 = 0 THEN 'BizzBuzz' --Divisible by 15 WHEN RowNum % 3 = 0 THEN 'Bizz' --Divisible by 3 WHEN RowNum % 5 = 0 THEN 'Buzz' --Divisible by 5 ELSE CAST(RowNum AS VARCHAR(10)) END AS DesiredResult FROM #Nums ORDER BY RowNum