473,385 Members | 1,492 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,385 software developers and data experts.

Compex SQL Query containing UNION, Needs Filtering

Hi there,

I am trying to do a UNION with slightly different queries, it appears to work but it now bring in another problem. The second part of the UNION need to have a an extra field value ("NULL") added thus to match the number of fields between the two select queries. The problem comes that I some have duplicate records and want to condense them down so that "Table_Form_Element_ID" has a single record against it but I want the record to be the one where (NOT (Form_Element_Server_Process_Code IS NULL)) AND (NOT (Form_Element_Site_Id IS NULL)) and disregard the other bogus records. However say this if (NOT (Form_Element_Server_Process_Code IS NULL)) AND (NOT (Form_Element_Site_Id IS NULL)) do not exist then display the records (NOT (Form_Element_Server_Process_Code IS NULL)) OR
(NOT (Form_Element_Site_Id IS NULL)).

The current query is producing the following:-



Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT Form_Storage_Process_Order, Form_Element_Server_Process_Code, Table_Form_Element_ID, Table_Form_Table_Name, Table_Form_Element_Key, Table_Form_Element_Name, Table_Form_Element_Type, Table_Form_Element_Length, Form_Element_Site_Id, Form_Id
  3. FROM (SELECT cTbl.Form_Storage_Process_Order AS Form_Storage_Process_Order, cTbl.Form_Element_Server_Process_Code AS Form_Element_Server_Process_Code, dTbl.Table_Form_Element_ID AS Table_Form_Element_ID, dTbl.Table_Form_Table_Name AS Table_Form_Table_Name, dTbl.Table_Form_Element_Key AS Table_Form_Element_Key, dTbl.Table_Form_Element_Name AS Table_Form_Element_Name, dTbl.Table_Form_Element_Type AS Table_Form_Element_Type, dTbl.Table_Form_Element_Length AS Table_Form_Element_Length, bTbl.Form_Element_Site_Id AS Form_Element_Site_Id, eTbl.Form_Id AS Form_Id
  4.      FROM WWWFORM_SITE_ELEMENT_LAYOUT aTbl INNER JOIN
  5.         WWWFORM_SITE_ELEMENT bTbl ON aTbl.Form_Element_Site_Id = bTbl.Form_Element_Site_Id INNER JOIN
  6.         WWWDATABASE_STORAGE_PROSESS_GROUP cTbl ON aTbl.Form_Element_Layout_Id = cTbl.Form_Element_Layout_Id INNER JOIN
  7.         WWWDATABASE_STORAGE_PROSESS_STRUCTURE dTbl ON cTbl.Table_Form_Element_ID = dTbl.Table_Form_Element_ID INNER JOIN
  8.         WWWFORM eTbl ON eTbl.Form_Storage_Process_Type_Id = cTbl.Form_Storage_Process_Type_Id
  9.      UNION
  10.      SELECT cTbl.Form_Storage_Process_Order AS Form_Storage_Process_Order, 
  11.        cTbl.Form_Element_Server_Process_Code AS Form_Element_Server_Process_Code, 
  12.        dTbl.Table_Form_Element_ID AS Table_Form_Element_ID, dTbl.Table_Form_Table_Name AS Table_Form_Table_Name, 
  13.        dTbl.Table_Form_Element_Key AS Table_Form_Element_Key, dTbl.Table_Form_Element_Name AS Table_Form_Element_Name, 
  14.        dTbl.Table_Form_Element_Type AS Table_Form_Element_Type, dTbl.Table_Form_Element_Length AS Table_Form_Element_Length, NULL, 
  15.        eTbl.Form_Id AS Form_Id
  16.      FROM WWWDATABASE_STORAGE_PROSESS_GROUP cTbl INNER JOIN
  17.          WWWDATABASE_STORAGE_PROSESS_STRUCTURE dTbl ON cTbl.Table_Form_Element_ID = dTbl.Table_Form_Element_ID INNER JOIN
  18.          WWWFORM eTbl ON eTbl.Form_Storage_Process_Type_Id = cTbl.Form_Storage_Process_Type_Id) DERIVEDTBL
  19. WHERE (NOT (Form_Element_Server_Process_Code IS NULL)) OR (NOT (Form_Element_Site_Id IS NULL)) AND (Form_Id = '1')
  20.  
If anyone knows how I can get around this problem I would be very grateful. Its giving me a headache. I am not familiar with If Else Clauses in SQL but I feel that it must be possible.

Thanks
Dec 15 '07 #1
0 1128

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

Similar topics

2
by: Gerry Abbott | last post by:
Hi All, I have one table with two tables linked to two index fields, tblMain, MainId, CashId, CreditId tblCash Cashid, CashValue tblCredit, CreditId, CreditValue Each record is either a...
7
by: RLN | last post by:
Re: Access 2000 I have three history tables. Each table contains 3 years worth of data. All three tables have a date field in them (and autonum field). Each table has the potential to contain...
1
by: Nicolae Fieraru | last post by:
Hi All, I want to find if there is a different way than the way I am working now. Lets say I have a table, tblCustomers containing address details. I want a report with all the customers from...
0
by: Jason | last post by:
I have a primary form which is used to enter/edit data in a table named Test_Results. On this primary form there is a subform which displays site addresses. This subform is linked to the primary...
2
by: Lenin Torres | last post by:
Hi everybody I have an Union Query that works fine. I used this query as the RecordSource for a Form. That Form is used as a subform in another form. Everything works fine, except for the "Filter...
15
by: laurenq uantrell | last post by:
Wondering if there is a physical or realistic limitation to the number of UNION statements I can create in a query? I have a client with approx 250 tables - the data needs to be kept in seperate...
2
by: AJ | last post by:
Hi all, I have this monster query (at least i think it is). SELECT c.ID, c.Company_Name, p., 1 As QueryNbr FROM (Company AS c LEFT JOIN Sale AS s ON c.ID = s.Company_ID) LEFT JOIN Package...
1
by: bgreenspan | last post by:
Hi Everyone, I'm back for some more expert help. Here's what I am doing and what I tried. My database has entries with Contract Names and Expiry Dates, among other fields. I have a form...
2
by: billelev | last post by:
Hi There, I am performing a UNION query on a Table containing % formatted values with a Query, also containing % formatted values. The resulting union query displays the table % values as...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.