Magic Numbers: Lessons Learned

Magic numbers will kill you.  I set up a stored procedure many years ago that included the following TSQL syntax:

HAVING (((tblMeet.SeasonID)=5) AND ((tblMeet.UseForPR)=1) AND ((tblMeet.IsCurrent)=0))

I remembered to change the magic number for a couple of years, but I didn’t change the seasonId at the beginning of this season (now on season 6) so erroneous results were generated (and some kids almost didn’t get a PR ribbon, which would suck).  I changed the syntax to this:

Declare @seasonId int

Set @SeasonId = (

      Select seasonId from tblSeason

      where SeasonDesc = Convert(varchar,YEAR(Getdate())))

and later on:

HAVING (((tblMeet.SeasonID)=@seasonId) AND ((tblMeet.UseForPR)=1) AND ((tblMeet.IsCurrent)=0))

And now I don’t have to remember this change next year.  Dear Jamie2011, you are welcome….

BTW: how cool is the intellisense in SQLServer 2008 Management Studio? Awesome Microsoft. Awesome.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: