by Peterg » Tue May 20, 2008 4:08 pm
I have created the following stored procedure which works but is just as slow as 32 seeks
Any ideas
Use iwscompa
go
IF OBJECT_ID ('usp_find_price') IS NOT NULL
DROP PROCEDURE usp_find_price
go
CREATE PROCEDURE usp_find_price
@mSite numeric(2),
@mCustType varchar(10),
@mCustNbr varchar(10),
@mUniqNbr varchar(10),
@mContainer varchar(10),
@mWaste varchar(10),
@mArea varchar(10),
@mDisposer varchar(10),
@mEffective datetime,
@result numeric (10)
AS
/*1*/
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custno = @mCustNbr or sp_custno is null) and
(uniq_nbr = @mUniqNbr or uniq_nbr is null) and
sp_contain = @mContainer and
(sp_waste = @mWaste or sp_waste is null) and
(sp_region = @mArea or sp_region is null) and
(sp_dispsit = @mDisposer or sp_dispsit is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
/*2*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custno = @mCustNbr or sp_custno is null) and
(uniq_nbr = @mUniqNbr or uniq_nbr is null) and
sp_contain = @mContainer and
(sp_waste = @mWaste or sp_waste is null) and
(sp_region = @mArea or sp_region is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*3*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custno = @mCustNbr or sp_custno is null) and
(uniq_nbr = @mUniqNbr or uniq_nbr is null) and
sp_contain = @mContainer and
(sp_waste = @mWaste or sp_waste is null) and
(sp_dispsit = @mDisposer or sp_dispsit is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*4*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custno = @mCustNbr or sp_custno is null) and
(uniq_nbr = @mUniqNbr or uniq_nbr is null) and
sp_contain = @mContainer and
(sp_waste = @mWaste or sp_waste is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*5*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custno = @mCustNbr or sp_custno is null) and
(uniq_nbr = @mUniqNbr or uniq_nbr is null) and
sp_contain = @mContainer and
(sp_region = @mArea or sp_region is null) and
(sp_dispsit = @mDisposer or sp_dispsit is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*6*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custno = @mCustNbr or sp_custno is null) and
(uniq_nbr = @mUniqNbr or uniq_nbr is null) and
sp_contain = @mContainer and
(sp_dispsit = @mDisposer or sp_dispsit is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*7*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custno = @mCustNbr or sp_custno is null) and
(uniq_nbr = @mUniqNbr or uniq_nbr is null) and
sp_contain = @mContainer and
(sp_dispsit = @mDisposer or sp_dispsit is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*8*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custno = @mCustNbr or sp_custno is null) and
(uniq_nbr = @mUniqNbr or uniq_nbr is null) and
sp_contain = @mContainer and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
IF @result = 0
/*9*/
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custno = @mCustNbr or sp_custno is null) and
sp_contain = @mContainer and
(sp_waste = @mWaste or sp_waste is null) and
(sp_region = @mArea or sp_region is null) and
(sp_dispsit = @mDisposer or sp_dispsit is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*10*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custno = @mCustNbr or sp_custno is null) and
sp_contain = @mContainer and
(sp_waste = @mWaste or sp_waste is null) and
(sp_region = @mArea or sp_region is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*11*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custno = @mCustNbr or sp_custno is null) and
sp_contain = @mContainer and
(sp_waste = @mWaste or sp_waste is null) and
(sp_dispsit = @mDisposer or sp_dispsit is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*12*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custno = @mCustNbr or sp_custno is null) and
sp_contain = @mContainer and
(sp_waste = @mWaste or sp_waste is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*13*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custno = @mCustNbr or sp_custno is null) and
sp_contain = @mContainer and
(sp_region = @mArea or sp_region is null) and
(sp_dispsit = @mDisposer or sp_dispsit is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*14*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custno = @mCustNbr or sp_custno is null) and
sp_contain = @mContainer and
(sp_dispsit = @mDisposer or sp_dispsit is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*15*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custno = @mCustNbr or sp_custno is null) and
sp_contain = @mContainer and
(sp_dispsit = @mDisposer or sp_dispsit is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*16*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custno = @mCustNbr or sp_custno is null) and
sp_contain = @mContainer and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*17*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custype = @mCustType or sp_custype is null) and
sp_contain = @mContainer and
(sp_waste = @mWaste or sp_waste is null) and
(sp_region = @mArea or sp_region is null) and
(sp_dispsit = @mDisposer or sp_dispsit is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*18*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custype = @mCustType or sp_custype is null) and
sp_contain = @mContainer and
(sp_waste = @mWaste or sp_waste is null) and
(sp_region = @mArea or sp_region is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*19*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custype = @mCustType or sp_custype is null) and
sp_contain = @mContainer and
(sp_waste = @mWaste or sp_waste is null) and
(sp_dispsit = @mDisposer or sp_dispsit is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*20*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custype = @mCustType or sp_custype is null) and
sp_contain = @mContainer and
(sp_waste = @mWaste or sp_waste is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*21*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custype = @mCustType or sp_custype is null) and
sp_contain = @mContainer and
(sp_region = @mArea or sp_region is null) and
(sp_dispsit = @mDisposer or sp_dispsit is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*22*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custype = @mCustType or sp_custype is null) and
sp_contain = @mContainer and
(sp_dispsit = @mDisposer or sp_dispsit is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*23*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custype = @mCustType or sp_custype is null) and
sp_contain = @mContainer and
(sp_dispsit = @mDisposer or sp_dispsit is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*24*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
(sp_custype = @mCustType or sp_custype is null) and
sp_contain = @mContainer and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*25*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
sp_contain = @mContainer and
(sp_waste = @mWaste or sp_waste is null) and
(sp_region = @mArea or sp_region is null) and
(sp_dispsit = @mDisposer or sp_dispsit is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*26*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
sp_contain = @mContainer and
(sp_waste = @mWaste or sp_waste is null) and
(sp_region = @mArea or sp_region is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*27*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
sp_contain = @mContainer and
(sp_waste = @mWaste or sp_waste is null) and
(sp_dispsit = @mDisposer or sp_dispsit is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*28*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
sp_contain = @mContainer and
(sp_waste = @mWaste or sp_waste is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*29*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
sp_contain = @mContainer and
(sp_region = @mArea or sp_region is null) and
(sp_dispsit = @mDisposer or sp_dispsit is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*30*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
sp_contain = @mContainer and
(sp_dispsit = @mDisposer or sp_dispsit is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*31*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
sp_contain = @mContainer and
(sp_dispsit = @mDisposer or sp_dispsit is null) and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
ELSE Return 0
/*32*/
IF @result = 0
SET @result = (SELECT sr_recno from skippric
where site_id = @msite and
sp_contain = @mContainer and
sp_effdate <= @mEffective and
(sp_deldate >= @mEffective or sp_deldate is null))
RETURN @result