Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Query help
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01398766
Message ID:
01398771
Views:
41
>Hi All,
>
>Is there a way without using a cursor to have only one Calc column instead of 3 (Calc1, Calc2 & Calc3) based on the condition below?
>
>
>select a.EDPNo, b.PVC, a.EachWeight,
>		c.VendNo, c.TermsPct, c.FrtCharge, c.FreeFrt, c.FrtAsPct, c.FrtChargePct,
>		--c.FreeFrt = 1
>		(b.PVC - (b.PVC * (c.TermsPct / 100))) as Calc1, 
>		--c.FrtAsPct = 1
>		(b.PVC + (b.PVC * (c.FrtChargePct / 100))) - (b.PVC * (c.TermsPct / 100)) as Calc2, 
>		--c.FreeFrt = 0 & c.FrtAsPct = 0
>		(b.PVC + (c.FrtCharge * a.EachWeight)) - (b.PVC * (c.TermsPct / 100))  as Calc3
>from DS1.dbo.ItemMst a join DS1.dbo.PItems b on a.EDPNo = b.EDPNo
>	 inner join DS1.dbo.VendorMst c on a.VendNo = c.VendNo
>
>
>Thanks,
>Daniel
select a.EDPNo, b.PVC, a.EachWeight,
		c.VendNo, c.TermsPct, c.FrtCharge, c.FreeFrt, c.FrtAsPct, c.FrtChargePct,
		CASE WHEN c.FreeFrt = 1 then 
		(b.PVC - (b.PVC * (c.TermsPct / 100))) 
		CASE WHEN c.FrtAsPct = 1 THEN
		(b.PVC + (b.PVC * (c.FrtChargePct / 100))) - (b.PVC * (c.TermsPct / 100))  
		CASE WHEN c.FreeFrt = 0 AND  c.FrtAsPct = 0 THEN
		(b.PVC + (c.FrtCharge * a.EachWeight)) - (b.PVC * (c.TermsPct / 100))  END as Calc
from DS1.dbo.ItemMst a join DS1.dbo.PItems b on a.EDPNo = b.EDPNo
	 inner join DS1.dbo.VendorMst c on a.VendNo = c.VendNo
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform