October 28, 2010 at 11:51 am
I have two similar tables: Purchases (idnum, trndate, amount) and Payments (idnum, trndate, amount). I would like to create a view that combines them into one with purchases being a negative number and payments a positive number but in the same column. Basically creating a new view by inserting both tables into the view and have it be something like: Transactions (idnum, trndate, amount).
October 28, 2010 at 12:06 pm
CREATE VIEW Transactions
AS
SELECT idnum,
trndate,
amount * -1 as amount
FROMPurchases
UNION ALL
SELECT idnum,
trndate,
amount
FROMPayments
GO
October 28, 2010 at 12:58 pm
Thank you, this worked perfectly.
October 28, 2010 at 1:25 pm
October 28, 2010 at 1:37 pm
That would work if the 2 tables were in fact related by idnum=idnum, but the OP did not say the tables were related.....just similar.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply