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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculation in Column 1

Status
Not open for further replies.

alexanderthegreat

IS-IT--Management
Sep 9, 2005
70
US
How can I created a calculation in a column from the following. I am tryin to make a grandtotal column out of dollar1, dollar2, and dollar3 fields respectivly.

SELECT dbo.RFQ.id AS rfqid, dbo.Users.UserID, dbo.RFQ.dollars1, dbo.RFQ.dollars2, dbo.RFQ.dollars3, dbo.RFQ.dollars4, dbo.RFQ.dollars5, dbo.RFQ.dollars6,
dbo.RFQ.dollars7, dbo.RFQ.dollars8, dbo.RFQ.dollars9, dbo.RFQ.dollars10, grandtotal(dollar1 + dollar2 + dollar3) AS Subtotal
FROM dbo.RFQ INNER JOIN
dbo.Users ON dbo.RFQ.uid = dbo.Users.UserID

Al
 
I believe this is what you want, I did a coalesce around the fields in case of NULL values

SELECT dbo.RFQ.id AS rfqid, dbo.Users.UserID, dbo.RFQ.dollars1, dbo.RFQ.dollars2, dbo.RFQ.dollars3, dbo.RFQ.dollars4, dbo.RFQ.dollars5, dbo.RFQ.dollars6,
dbo.RFQ.dollars7, dbo.RFQ.dollars8, dbo.RFQ.dollars9, dbo.RFQ.dollars10,
coalesce(dbo.RFQ.dollars1,0)+ coalesce(dbo.RFQ.dollars2,0)+ coalesce(dbo.RFQ.dollars3,0) AS Subtotal
FROM dbo.RFQ INNER JOIN
dbo.Users ON dbo.RFQ.uid = dbo.Users.UserID

Denis The SQL Menace
SQL blog:
Personal Blog:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top