The Daily WTF
Stored procedures are a bit of a WTF breeding ground. Your average stored procedure language is more limited than your average general purpose language, the syntax is usually clunkier, and everything is so data-focused that implementing logic beyond simplistic processes can be more challenging than one would expect.
Of course, this gets harder if you don’t bother to learn how to do string concatenation. Darrin found an example of that while debugging a store procedure:
if @_DistType = 1 begin set @_Query = dbo.GetQuery(‘DistType1’); execute sp_executeSQL @_Query end if @_DistType = 2 begin set @_Query = dbo.GetQuery(‘DistType2’); execute sp_executeSQL @_Query end if @_DistType = 3 begin set @_Query = dbo.GetQuery(‘DistType3’); execute sp_executeSQL @_Query end — snip if @_DistType = 74 begin set @_Query = dbo.GetQuery(‘DistType74’); execute sp_executeSQL @_Query end if @_DistType = 75 begin set @_Query = dbo.GetQuery(‘DistType75’); execute sp_executeSQL @_Query end
Note how each branch of the
To read the full article click on the 'post' link at the top.