Re: SQL express performens lagg
- From: Ed Murphy <emurphy42@xxxxxxxxxxxx>
- Date: Wed, 18 Oct 2006 02:38:04 GMT
Jacob Ipsen wrote:
Select 1 as DiscNiv ,DiscountQuantity,DiscountPercent,DiscountAm from ProdPrDcMat where ((DiscountPercent <> 0)or (DiscountAm <> 0)) and ((ProdNo = @ProdNo) and (barcode = @Barcode) and (DiscountQuantity <= @Quantity) and (FrDt < @DDate and ToDt > @DDate )) UNION
Select 2 as DiscNiv ,DiscountQuantity,DiscountPercent,DiscountAm from ProdPrDcMat where ((DiscountPercent <> 0)or (DiscountAm <> 0)) and ((ProdNo = @ProdNo) and (barcode = @Barcode) and (FrDt < @DDate and ToDt > @DDate )) UNION
Select 3 as DiscNiv ,DiscountQuantity,DiscountPercent,DiscountAm from ProdPrDcMat where ((DiscountPercent <> 0)or (DiscountAm <> 0)) and ((ProdNo = @ProdNo) and (barcode = @Barcode) and (DiscountQuantity <= @Quantity)) UNION
Select 4 as DiscNiv ,DiscountQuantity,DiscountPercent,DiscountAm from ProdPrDcMat where ((DiscountPercent <> 0)or (DiscountAm <> 0)) and ((ProdNo = @ProdNo) and (barcode = @Barcode)) UNION
Select 5 as DiscNiv ,DiscountQuantity,DiscountPercent,DiscountAm from ProdPrDcMat where ((DiscountPercent <> 0)or (DiscountAm <> 0)) and ((ProdNo = @ProdNo) and (DiscountQuantity <= @Quantity) and (FrDt < @DDate and ToDt > @DDate )) UNION
Select 6 as DiscNiv ,DiscountQuantity,DiscountPercent,DiscountAm from ProdPrDcMat where ((DiscountPercent <> 0)or (DiscountAm <> 0)) and ((ProdNo = @ProdNo) and (FrDt < @DDate and ToDt > @DDate )) UNION
Select 7 as DiscNiv ,DiscountQuantity,DiscountPercent,DiscountAm from ProdPrDcMat where ((DiscountPercent <> 0)or (DiscountAm <> 0)) and ((ProdNo = @ProdNo) and (DiscountQuantity <= @Quantity)) UNION
Select 8 as DiscNiv ,DiscountQuantity,DiscountPercent,DiscountAm from ProdPrDcMat where ((DiscountPercent <> 0)or (DiscountAm <> 0)) and (ProdNo = @ProdNo and (DiscountQuantity = 0))
Order by DiscountQuantity,DiscNiv asc
Why not replace this monstrosity with the following:
select
case
when barcode = @Barcode
and @Quantity >= DiscountQuantity
and @DDate between FrDt and ToDt
then 1
when barcode = @Barcode
and @Quantity < DiscountQuantity
and @DDate between FrDt and ToDt
then 2
when barcode = @Barcode
and @Quantity >= DiscountQuantity
and @DDate not between FrDt and ToDt
then 3
when barcode = @Barcode
and @Quantity < DiscountQuantity
and @DDate not between FrDt and ToDt
then 4
when barcode <> @Barcode
and @Quantity >= DiscountQuantity
and @DDate between FrDt and ToDt
then 5
when barcode <> @Barcode
and @Quantity < DiscountQuantity
and @DDate between FrDt and ToDt
then 6
when barcode <> @Barcode
and @Quantity >= DiscountQuantity
and @DDate not between FrDt and ToDt
then 7
when barcode <> @Barcode
and @Quantity < DiscountQuantity
and @DDate not between FrDt and ToDt
then 8
else -1
end as DiscNiv,
DiscountQuantity,
DiscountPercent,
DiscountAm
from ProdPrDcMat
where (DiscountPercent <> 0 or DiscountAm <> 0)
and ProdNo = @ProdNo
order by DiscountQuantity, DiscNiv
.
- Follow-Ups:
- Re: SQL express performens lagg
- From: Jacob Ipsen
- Re: SQL express performens lagg
- References:
- SQL express performens lagg
- From: Jacob Ipsen
- Re: SQL express performens lagg
- From: abx78
- Re: SQL express performens lagg
- From: Jacob Ipsen
- SQL express performens lagg
- Prev by Date: Re: Precision in SQL server 2000
- Next by Date: Re: Precision in SQL server 2000
- Previous by thread: Re: SQL express performens lagg
- Next by thread: Re: SQL express performens lagg
- Index(es):
Relevant Pages
|
Loading