Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
davidpardoe
Constraint Violating Yak Guru
324 Posts |
Posted - 2001-07-18 : 05:28:33
|
| Can anyone manage the following more efficiently than my first stab...I have the following tables:-Customer--------cust_reflinked_cust_refLimit-----cust_reflimitThe customer table has a unique ref number (cust_ref). If the customer is linked to another (ie. through a joint account) then there will be a linked ref number (linked_cust_ref). I need to calculate the total limit for the customer by adding the limits for cust_ref and linked_cust_ref.My implementation at the moment involves creating temporary tables, first for the cust_ref and then for the linked_cust_ref and then merging these into a final table. Anyone come up with a way of doing it in less than 3 selects:-select customer.cust_ref,limit.limitinto primary_limit from customer on customer.cust_ref=limit.cust_refselect customer.cust_ref,limit.limitinto secondary_limit from customer on customer.linked_cust_ref=limit.cust_refselect primary_limit.cust_ref,total_limit=primary_limit.limit+seconday_limit.limitfrom primary_limit on primary_limit.cust_ref=secondary_limit.cust_ref |
|
|
|
|
|