473,387 Members | 1,485 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Having problems creating a Union Query

I have been trying to figure out how to create a Union Query between two tables with different data with one field containing similiar data.


I have 2 tables:

NoteData & IndirectData

The common field (although named differently in the two tables) contains TaxID information. I am triying to do Sum calculations at the same time in the qury and that may be my probelm. See below:
Expand|Select|Wrap|Line Numbers
  1. SELECT TreevNoteData.Account_Primary_Borrower_Tax_ID_Nbr AS TaxID,
  2.              Sum(TreevNoteData.Note_Current_Balance) AS SumOfNote_Current_Balance,
  3.              Sum(TreevNoteData.Note_Ledger_Balance) AS SumOfNote_Ledger_Balance,
  4.              Sum(TreevNoteData.Note_Appraisal_Value) AS SumOfNote_Appraisal_Value,
  5. Sum(IIf(Len([TreevNoteData]![Note_Collateral_Code])=2,IIf([TreevNoteData]![Note_Collateral_Code]="A1",[TreevNoteData]![Note_Ledger_Balance],0),[TreevNoteData]![Note_Ledger_Balance])) AS [Unsecured Bal],
  6. Sum(IIf([TreevNoteData]![Note_Type_Code] In ("100","101","190","402"),IIf(Len([TreevNoteData]![Note_Collateral_Code])=2,IIf([TreevNoteData]![Note_Collateral_Code]="A1",[TreevNoteData]![Note_Ledger_Balance],0),[TreevNoteData]![Note_Ledger_Balance]),0)) AS ComUnsecBal,
  7. Sum(IIf([TreevNoteData]![Note_Type_Code] In ("100","101","190","402"),[TreevNoteData]![Note_Ledger_Balance],0)) AS ComBal,
  8.              NULL,
  9.              NULL
  10. FROM TreevNoteData 
  11. UNION ALL
  12. SELECT TreevIndirectData.Endr_Customer_Tax_ID_Number AS TaxID,
  13.              Sum(TreevIndirectData.Indirect_Liab_Limit_Amount) AS SumOfIndirect_Liab_Limit_Amount, 
  14.              Sum(TreevIndirectData.Indirect_Liab_Limit_Percent) AS SumOfIndirect_Liab_Limit_Percent, 
  15.              Sum(TreevIndirectData.Note_Cmmt_Bank_Share_Ledger_Balance) AS SumOfNote_Cmmt_Bank_Share_Ledger_Balance,
  16.              Sum(TreevIndirectData.Note_Cmmt_Current_Balance) AS SumOfNote_Cmmt_Current_Balance, 
  17.              Sum(TreevIndirectData.Note_Cmmt_Ledger_Balance) AS SumOfNote_Cmmt_Ledger_Balance,
  18.              Sum(TreevIndirectData.Note_Cmmt_Original_Credit_Line_Amt) AS SumOfNote_Cmmt_Original_Credit_Line_Amt, 
  19.              Sum(TreevIndirectData.Note_Cmmt_Unused_Credit_Line_Amount) AS SumOfNote_Cmmt_Unused_Credit_Line_Amount, 
  20.              Sum(TreevIndirectData.Note_Cmmt_Used_Credit_Line_Amount) AS SumOfNote_Cmmt_Used_Credit_Line_Amount FROM TreevIndirectData
  21. GROUP BY TaxID;
Mar 29 '10 #1
1 1440
NeoPa
32,556 Expert Mod 16PB
I suggest you find a cut-down version which exhibits the same symptoms that you want help with. Most of this SQL is entirely unrelated to your question so expecting others to wade through this just to find your problem is not reasonable.
Mar 29 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: jtwright | last post by:
I've got a view that creates a parent child relationship, this view is used in Analysis Services to create a dimension in a datastore. This query tends to deadlock after about 10 days of running...
2
by: edself | last post by:
Greetings, I am semi-new to Access and have a query question. I presume the solution is easy, but need some help. I have created a database with a Contact table. The contact table contains...
6
by: Jamal | last post by:
I am working on binary files of struct ACTIONS I have a recursive qsort/mergesort hybrid that 1) i'm not a 100% sure works correctly 2) would like to convert to iteration Any comments or...
1
by: CrystalDBA | last post by:
I usually design applications in SQL Server and Crystal Reports. I now need to create a crystal report on an MS Access database. I have two tables: Services: Date datetime Entry text...
9
by: Jeremy | last post by:
I have a situation where i am trying to run two query's and retrieve one record from each query, then using Union combine them into one recordset. The First Query is strait forward and should just...
7
by: rcamarda | last post by:
I wish to build a table based on values from another table. I need to populate a table between two dates from another table. Using the START_DT and END_DT, create records between those dates. I...
5
by: BillCo | last post by:
I've encountered a problem while using ADO to save query objects. Union queries created normally (via the interface) appear in adox catelog.procedures rather than catelog.views. This is reasonably...
5
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data from 2005/01/01 ~ 2007/05/xx in single big...
7
by: pbd22 | last post by:
Hi. I really need some advice on fine-tuning a stored procedure that is the meat of the search logic on my site. Customers are allowed to save searches, which dumps the search logic in a table...
0
by: rj041284 | last post by:
i have completed these q. in sql but unable to do it in pl/sql let me help or give me path to do it Exercises : Q 1) Display department number and sum of the salaries of employees...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.