Hello All,

Can some one help me how to write query for finding the profi per unit using SQL server 2005/2008. I have got a unit table which contains UnitId and Quantity and the other table which contains cost price, selling price and the Unit Id.

Thank you

Recommended Answers

All 2 Replies

Hi pradvin and welcome to DaniWeb :)

You will need to join your tables to get all of the information that you need. The syntax for a join statement is like so:

-- select which columns you need
SELECT Table1.UnitID, Table1.Quantity, Table2.CostPrice, Table2.SellingPrice
-- from which table
FROM Table1
-- join to the second table
INNER JOIN Table2
-- describe how the tables are related, note that an inner join requires all of the fields in the ON clause to be non-null
ON Table1.UnitID = Table2.UnitID

This is the basic format you will need. I will let you have a play to see if you can work out how to manipulate the above query and get the unit profit.

You need to mention the relation between the tables.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.