title: SQL Stored Procs Null Parameters for a search of item
body: <p>I am creating a SQL stored procedure that will be used for the search of an item. I am allowing the user to search by item code or UPC. Thus, I need to be able to allow my parameters to be null. I think I'm close, however, when I execute this stored procedure it returns too many results when I am expecting only one. </p>
  
  <p>Here's what I have: </p>
  
  <pre><code>  @itm_ItemCode int,
    @itm_UPC varchar(11)
  
  SELECT 
       ITEM_CODE as itm_itemcode 
      ,UPC_CODE as itm_upc
      ,[DESCRIPTION] as itm_description
      ,BASE_PRICE as itm_regularcost
  
  FROM ITEM_TABLE 
      where (ITEM_CODE = @itm_ItemCode or @itm_ItemCode IS NULL) 
            OR (UPC_CODE = @itm_UPC or @itm_UPC IS NULL) 
  </code></pre>
  
  <p>Here are a few examples of what I have for my EXEC statement when I try to test my stored procedure: (Is this how I'm suppose to write my EXEC statements?</p>
  
  <pre><code>EXEC stp_ItemSearch null, 71591010583
  EXEC stp_ItemSearch 300, null
  </code></pre>
  
  <p>Thank you for your help! </p>
  
  <p>P.S. I'm using SQL Server Manager </p>