Skip to content

Instantly share code, notes, and snippets.

@othtim
Last active December 19, 2015 09:59
Show Gist options
  • Select an option

  • Save othtim/5936805 to your computer and use it in GitHub Desktop.

Select an option

Save othtim/5936805 to your computer and use it in GitHub Desktop.
fizzbuzz tsql
IF OBJECT_ID ( 'dbo.fb', 'P' ) IS NOT NULL
drop procedure dbo.fb;
GO
CREATE PROCEDURE dbo.fb (@int int)
AS
set @int = @int + 1
select @int,
case
when (@int % 3 = 0) then 'fizz' --'fizz'
when (@int % 5 = 0) then 'buzz' --'buzz'
else cast(@int as char)
end
execute dbo.fb @int
GO
execute dbo.fb 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment