select p.UBSAccountingDepartmentName,
c.Description,
p.UBSProductBrand,
p.UBSProductNumber,
p.UBSDescription,
p.UPCNumber,
p.CPRDNumber
INTO #Temp
from APLChainProduct acp, Product p, Category c
where acp.ChainNumber = @chain_code
and acp.ProductNumber = p.UBSProductNumber
and c.UBSProductCategory = p.UBSProductCategory
select * from #temp
where
convert(varchar, p.UBSProductNumber) like @product_number
and (p.CPRDNumber is null or p.CPRDNumber like @CPRD_number)
and (p.UBSDescription is null or p.UBSDescription like @description)
and (p.UPCNumber is null or p.UPCNumber like @UPCCode)
and (p.UBSProductBrand is null or p.UBSProductBrand like @brand)
and (p.UBSAccountingDepartmentName is null or p.UBSAccountingDepartmentName like @category)
you could even enhance it a bit:
select
ISNULL(p.UBSProductBrand, @brand) AS UBSProductBrand,
ISNULL( p.UBSProductNumber,@product_number) AS UBSProductNumber,
ISNULL(p.UBSDescription, @description) AS Description,
ISNULL(p.UPCNumber, @UPCCode) AS UPCNumber,
ISNULL(p.CPRDNumber, @CPRD_number) AS CPRDNumber,
ISNULL(p.UBSAccountingDepartmentName, @category) AS UBSAccountingDepartmentName
INTO #Temp
from APLChainProduct acp, Product p, Category c
where acp.ChainNumber = @chain_code
and acp.ProductNumber = p.UBSProductNumber
and c.UBSProductCategory = p.UBSProductCategory
Then you can:
select * from #temp
where
p.UBSProductNumber like @product_number OR
p.CPRDNumber like @CPRD_number OR
p.UBSDescription like @description OR
p.UPCNumber like @UPCCode OR
p.UBSProductBrand like @brand OR
p.UBSAccountingDepartmentName like @category)