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

How would this SQL look?? 1

Status
Not open for further replies.

vmon

IS-IT--Management
Feb 14, 2002
74
0
0
US
I need some direction on how to set this SQL up.

I have a temporary table for a report. The table has three columns and for example two records, there will actually a lot more. I want to insert a new record with a calculated difference between the amount the two records for a specific customer. A customer would never have more than two records. Example of what I am trying to do.

Customer Type Amount
CustA TypeA 100.00
CustA TypeB 25.00
CustA TypeD 75.00 /* New record added by insert

Rookie still learning,
vmon
 
Code:
insert into tempTable
select distinct customer, 'TypeD',
(select amount from tempTable where type = 'TypeA'
  and customer = t.customer ) -
(select amount from tempTable where type = 'TypeB'
  and customer = t.customer ) from tempTable t
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top