Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
Hi,

I have two tables

This is the first table

Godownid --> Activity --> Time --> Qty
1001 --> Loading --> Day --> 10
1002 --> Unloading --> Night --> 20
1003 --> Crossing --> Day --> 30

This is the second table

GodownId --> LoadingDayRate --> LoadingN8Rate --> UnloadingDayRate --> UnloadingN8rate -->CrossingDayRate --> Crossing Night Rate

1001 --> 10 --> 20 --> 30 --> 40 --> 50 --> 60


I want to get consolidate report like qty * price with activity and time...

Please help me...

With Regards,
Srinivas.
Posted
Comments
gvprabu 19-Jun-13 11:26am    
Give the formula.... U need to multiply by qty * price and what is activity and time?
nsvrao 19-Jun-13 11:32am    
LoadingDayRate (second table) * Day Qty (first table)
UnLoadingDayRate (second table) * Day Qty (first table)
CrossingDayRate (second table) * Day Qty (first table)

Finally I want like this

Godown,Activity,Time,Qty,price
1001,Loading,Day,10,10*10=100
gvprabu 19-Jun-13 11:34am    
I posted the solution... check and confirm
gvprabu 19-Jun-13 11:40am    
I updated my solution, as per ur request...
nsvrao 19-Jun-13 12:31pm    
Thank you very much Prabhu.. for your fast reply... It works for me..

1 solution

Hi,

Check the below Query....

SQL
SELECT T.GodownId, 
       T.Activity,
       T.Time,
       T.Qty,
       T.Amount,
       (T.Qty*T.Amount) 'CalculatedAmount'
FROM (SELECT T1.GodownId,T1.Activity,T1.Time,T1.Qty,
	(CASE WHEN T1.Activity='Loading' AND T1.Time='Day' THEN T2.LoadingDayRate
	      WHEN T1.Activity='Loading' AND T1.Time='Night' THEN T2.LoadingN8Rate
	      WHEN T1.Activity='Unloading' AND T1.Time='Day' THEN T2.UnloadingDayRate
	      WHEN T1.Activity='Unloading' AND T1.Time='Night' THEN T2.UnloadingN8rate
	      WHEN T1.Activity='Crossing' AND T1.Time='Day' THEN T2.CrossingDayRate
	      WHEN T1.Activity='Crossing' AND T1.Time='Night' THEN T2.CrossingNightRate
	 ELSE 0 END) 'Amount' 
FROM First_Table T1
INNER JOIN Second_Table T2 On T2.GodownId=T1.GodownId) T 

Regards,
GVPrabu
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900