It was Anthony's second day on the job, and the sixth time he thought to himself, What The Fuuuuuhhhggggg, while searching through the code. At least, he thought that he kept that last sentiment to himself.

Not a moment later, his coworker asked "what is it?" and then scooted his chair over to see Anthony staring at the following code, mouth agape.

declare @lnFirstName   varchar(255)
declare @lnLastName    varchar(255)
declare @lnEmailaddr   varchar(255)
declare @lnTitle       varchar(255)
declare @lnCompany     varchar(255)
declare @lnAddress     varchar(255)
declare @lnCity        varchar(255)
declare @lnState       varchar(255)
declare @lnZip         varchar(255)
declare @lnCountry     varchar(255)
declare @lnPhone       varchar(255)
declare @lnFax         varchar(255)

select
    @lnSitr0100Id      = max([Sitr0100Id])    
from 
    Sitr0110
where 
    [Sitr0110Id]       = @lnSitr0110Id

/* get local variable set with data from record if found */
select
     @lnFirstName      = [FirstName]
    ,@lnLastName       = [LastName]     
from
    Sitr0100
where
    [Sitr0100Id]       = @lnSitr0100Id

 /* reset nulls whether found or not */
select
     @lnFirstName      = isnull(@lnFirstName,'')
    ,@lnLastName       = isnull(@lnLastName,'')


select
    @lnEmailaddr       = [EmailAddress]
from
    sitr0100
where
    [Sitr0100Id]       = @lnSitr0100Id

select
    @lnTitle           = [Title]
from
    sitr0100
where
    [Sitr0100Id]       = @lnSitr0100Id
if @lnTitle is null
    begin
    set @lnTitle       = ''
    end

select
    @lnCompany         = [Company]
from
    sitr0100
where
    [Sitr0100Id]       = @lnSitr0100Id
if @lnCompany is null 
    begin
    set @lnCompany     = ''
    end

select
    @lnAddress         = [Address1]
from
    sitr0100
where
    [Sitr0100Id]       = @lnSitr0100Id
if @lnAddress is null 
    begin
    set @lnAddress     = ''
    end

select
    @lnCity            = [City]
from
    sitr0100
where
    [Sitr0100Id]       = @lnSitr0100Id
if @lnCity is null 
    begin
    set @lnCity        = ''
    end

select
    @lnState           = [State]
from 
    sitr0100
where
    [Sitr0100Id]       = @lnSitr0100Id
if @lnState is null 
    begin
    set @lnState       = ''
    end

select
    @lnZip             = [Zip]
from
    sitr0100
where
    [Sitr0100Id]       = @lnSitr0100Id
if @lnZip is null 
    begin
    set @lnZip         = ''
    end

select
    @lnCountry         = [Country]
from
    sitr0100
where
    [Sitr0100Id]       = @lnSitr0100Id
if @lnCountry is null 
    begin
    set @lnCountry     = ''
    end

select
    @lnPhone           = [Phone]
from
    sitr0100
where
    [Sitr0100Id]       = @lnSitr0100Id
if @lnPhone is null 
    begin
    set @lnPhone       = ''
    end

select
    @lnFax             = [Fax]
from    
     sitr0100
where
    [Sitr0100Id]       = @lnSitr0100Id

if @lnFax is null 
    begin
    set @lnFax         = ''
    end

select
    [Response]         = @lnSitr0110Id
   ,[First]            = @lnFirstName
   ,[Last]             = @lnLastName
   ,[Email]            = @lnEmailaddr
   ,[Title]            = @lnTitle
   ,[Company]          = @lnCompany
   ,[Address]          = @lnAddress
   ,[City]             = @lnCity
   ,[State]            = @lnState
   ,[Zip]              = @lnZip
   ,[Country]          = @lnCountry
   ,[Phone]            = @lnPhone
   ,[Fax]              = @lnFax
   ,[New]              = @lnNew    
   ,[Sitr0100Id]       = @lnSitr0100Id

"It's actually better this way," Anthony's coworker said unsarcastically, "you get a lot more control over things when you need to change things later."

It was going to be a really long contract.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!