Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help me

I want create view from two table with relationship

the first table have 6 Column

Id TariffPointsMainId TariffPointsSubId Discreption Notes Quantity
1 1 2 oooo sss 200
2 1 3 ooooo sss 100
3 1 4 oooooo sss 300


related with second table

Id ParentId TariffName Price
1 0 Steel 0
2 1 SteelSony 200
3 1 SteelNokia 300
4 1 SteelBerry 400

and I have Create View

TariffPointsMainName TariffPointsMainName GrossTotal
Steel SteelSony 40000
Steel SteelNokia 30000
Steel SteelBery 120000

Please Help Me
Posted

1 solution

Hi,
SQL
-- Check the following Select Statement, If its working fine for all your Data then make as VIEW using this SQL Statement
SELECT T2.TariffName 'TariffPointsMainName', T1.TariffName 'TariffPointsChildName',
ISNULL((SELECT NotesQuantity FROM Table1 WHERE TariffPointsSubId=T2.ParentId AND TariffPointsMainId=T2.ID),0) * T2.Price 'GrossTotal'
FROM Table2 T1
INNER JOIN Table2 T2 ON T1.ID = T2.ParentId 
WHERE T2.ParentId <>0
ORDER BY T2.ParentId, T2.ID

Regards,
GVPrabu
 
Share this answer
 

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