Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL help to combine two tables
Message
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00531538
Message ID:
00531561
Views:
9
This message has been marked as the solution to the initial question of the thread.
Try following code. IIF should give you correct cust_id and NVL'll convert .Null. into 0
SELECT ;
	IIF( ISNULL(tCredit.cust_id1), tDebit.cust_id1, tCredit.cust_id1) AS cust_id1, ;
	IIF( ISNULL(tCredit.cust_id1), tDebit.cust_id2, tCredit.cust_id2) AS cust_id2, ;
	NVL(tDebit.amt, 0) AS Debitamt, NVL(tCredit.amt,0) AS Creditamt ;
	FROM tCredit ;
	FULL OUTER JOIN tDebit ON tCredit.cust_id1 = tDebit.cust_id1 ;
				AND tCredit.cust_id2 = tDebit.cust_id2 ;
	INTO CURSOR CredIDebit						
>I have two tables: tCredit and tDebit. Each has three fields: cust_id1, cust_id2, amt. Want to produce a table that has cust_id1, cust_id2, credit_amt, debit_amt.
>
>There are cust_id1/cust_id2 records in tCredit that are not tDebit and visa versa. So they would have 0 in the non-matching amount field.
>
>I tried a FULL OUTER JOIN but could not get the cust_id1/cust_id2 to have a value for both the tCredit and tDebit non-matches.
>
>Thanks
>
>Brenda
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform