Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 query

Author  Topic 

gagani
Posting Yak Master

112 Posts

Posted - 2012-01-12 : 11:22:53
i have two tables
table1:
orderid netvalue
101 1000
102 2000
103 3000

table2:
orderid percentage
101 0.1
102 0.1

I want the output as follows:
orderid net(netvalue- (netvalue*percentage))
101 900
102 1800
103 3000

please note that table2 dont have all orderids. so percentage is considered 0 for that particular orderid

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-12 : 11:27:12
SELECT t1.OrderId, t1.netValue - (t1.netValue * COALESCE(t2.percentage,0)) AS net
FROM table1 t1 LEFT JOIN table2 t2
ON t1.OrderId = t2.OrderId

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -