How NOT to Code - Example 8
So I mentioned that I would bounce around with languages a bit. Since many of us in the RIA development world do use Sql Server, I figure this would be nice to cover.
This is actually a fairly new one I learn at the local sql server user group. I actually would be surprised if anyone finds the problem in this one. This is really a dba level challenge, but it's good for programmers to know.
create procedure CustomerLookup
@CustomerID int = NULL
,@PersonID int = NULL
select * from Sales.Customer CU
inner join sales.salesorderheader sh on sh.customerid = cu.customerid
inner join sales.salesorderdetail sd on sd.salesorderID = sh.salesorderid
where (cu.customerid = @CustomerID or @CustomerID is NULL) and
(cu.personID = @PersonID or @PersonID is NULL)