Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another Convert Jet to TSQL

Status
Not open for further replies.

RobFreeman

Programmer
Sep 20, 2005
2
US
The following works fine in Access 2003. However, in SQL it fails with "Invalid Column Name".

In Access you can create a new column, in our case "Margin" and immediately use it in futher calculations. I am a total rookie in TSQL so would like some ideas on the best way to solve this type of problem.


SELECT
Products.ProductName,
Products.UnitPrice,
Products.Cost,
[UnitPrice]-[Cost] AS Margin,
[Margin]*100/[UnitPrice] AS MarginPct
FROM Products;
 
You just need to copy the 'margin' column, like this...

SELECT
Products.ProductName,
Products.UnitPrice,
Products.Cost,
[UnitPrice]-[Cost] AS Margin,
([UnitPrice]-[Cost])*100/[UnitPrice] AS MarginPct
FROM Products

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top