I have 2 separate queries, which effectively are the same except they
draw data from separate tables. Both tables are (design-wise)
identical, only the data is different. for each query, there are 2
tables with a standard LEFT JOIN. One field of the query is calculated,
looking for a NULL in one table, and then using a field from the second
table in that case. One query looks like this:
PARAMETERS [Month] Text ( 255 );
SELECT GR_CUSTOMER.CST_FIRSTNAME, IIf(GR_CUSTOMER!CST_LASTNAME Is Not
Null,GR_CUSTOMER!CST_LASTNAME,GR_FAMILY!FAM_FAMILY NAME) AS LASTNAME,
GR_CUSTOMER.CST_BIRTHDATE, GR_FAMILY.FAM_ADDRESS1,
GR_FAMILY.FAM_ADDRESS2, GR_FAMILY.FAM_CITY, GR_FAMILY.FAM_STATE,
GR_FAMILY.FAM_ZIPCODE
FROM GR_CUSTOMER INNER JOIN GR_FAMILY ON GR_CUSTOMER.FAMILY_ID =
GR_FAMILY.FAMILY_ID
WHERE (((MonthName(DatePart("m",[CST_BIRTHDATE]),1))=[Month]));
We'll call this query QUERY1. This query executes PERFECTLY. The second
query (we'll call it QUERY2) is identical, except for substituting the
tables names where appropriate.
However, when I try to creat a UNION query, like
Table QUERY1 UNION Table QUERY2
the calculated field, "LASTNAME", is EMPTY!
I have attempted to use the Nz() function in place of the IIF()
statement (it behaves the same way). If I use any other non-calculated
field for the ALIAS field "LASTNAME", the full UNION query works fine
as well!
Any thoughts as to what might cause such a problem with the ALIAS on a
calculated field?
Thanks in advance,
Mike 3 2205
Mike, I'm not sure why it's not working correctly but see if these
suggestions solve the problem:
1. Try creating one query, instead of UNIONing 2 queries each with their own
parameters.
2. Use Nz() rather than the IIf() statement.
3. Take the month number as the parameter.
You will end up with something like this:
PARAMETERS [MonthNumber] Short;
SELECT GR_CUSTOMER.CST_FIRSTNAME,
Nz(GR_CUSTOMER.CST_LASTNAME, GR_FAMILY.FAM_FAMILYNAME) AS LASTNAME,
GR_CUSTOMER.CST_BIRTHDATE, GR_FAMILY.FAM_ADDRESS1,
GR_FAMILY.FAM_ADDRESS2, GR_FAMILY.FAM_CITY, GR_FAMILY.FAM_STATE,
GR_FAMILY.FAM_ZIPCODE
FROM GR_CUSTOMER INNER JOIN GR_FAMILY
ON GR_CUSTOMER.FAMILY_ID = GR_FAMILY.FAMILY_ID
WHERE Month([CST_BIRTHDATE]) = MonthNumber
UNION
SELECT Table2.Firstname, ...
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
<mi***@vmsmailingservices.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com... I have 2 separate queries, which effectively are the same except they draw data from separate tables. Both tables are (design-wise) identical, only the data is different. for each query, there are 2 tables with a standard LEFT JOIN. One field of the query is calculated, looking for a NULL in one table, and then using a field from the second table in that case. One query looks like this:
PARAMETERS [Month] Text ( 255 ); SELECT GR_CUSTOMER.CST_FIRSTNAME, IIf(GR_CUSTOMER!CST_LASTNAME Is Not Null,GR_CUSTOMER!CST_LASTNAME,GR_FAMILY!FAM_FAMILY NAME) AS LASTNAME, GR_CUSTOMER.CST_BIRTHDATE, GR_FAMILY.FAM_ADDRESS1, GR_FAMILY.FAM_ADDRESS2, GR_FAMILY.FAM_CITY, GR_FAMILY.FAM_STATE, GR_FAMILY.FAM_ZIPCODE FROM GR_CUSTOMER INNER JOIN GR_FAMILY ON GR_CUSTOMER.FAMILY_ID = GR_FAMILY.FAMILY_ID WHERE (((MonthName(DatePart("m",[CST_BIRTHDATE]),1))=[Month]));
We'll call this query QUERY1. This query executes PERFECTLY. The second query (we'll call it QUERY2) is identical, except for substituting the tables names where appropriate.
However, when I try to creat a UNION query, like Table QUERY1 UNION Table QUERY2
the calculated field, "LASTNAME", is EMPTY!
I have attempted to use the Nz() function in place of the IIF() statement (it behaves the same way). If I use any other non-calculated field for the ALIAS field "LASTNAME", the full UNION query works fine as well!
Any thoughts as to what might cause such a problem with the ALIAS on a calculated field?
Thanks in advance, Mike mi***@vmsmailingservices.com wrote in news:1135636101.010614.85020
@g44g2000cwa.googlegroups.com: I have 2 separate queries, which effectively are the same except they draw data from separate tables. Both tables are (design-wise) identical, only the data is different. for each query, there are 2 tables with a standard LEFT JOIN. One field of the query is calculated, looking for a NULL in one table, and then using a field from the second table in that case. One query looks like this:
PARAMETERS [Month] Text ( 255 ); SELECT GR_CUSTOMER.CST_FIRSTNAME, IIf(GR_CUSTOMER!CST_LASTNAME Is Not Null,GR_CUSTOMER!CST_LASTNAME,GR_FAMILY!FAM_FAMILY NAME) AS LASTNAME, GR_CUSTOMER.CST_BIRTHDATE, GR_FAMILY.FAM_ADDRESS1, GR_FAMILY.FAM_ADDRESS2, GR_FAMILY.FAM_CITY, GR_FAMILY.FAM_STATE, GR_FAMILY.FAM_ZIPCODE FROM GR_CUSTOMER INNER JOIN GR_FAMILY ON GR_CUSTOMER.FAMILY_ID = GR_FAMILY.FAMILY_ID WHERE (((MonthName(DatePart("m",[CST_BIRTHDATE]),1))=[Month]));
We'll call this query QUERY1. This query executes PERFECTLY. The second query (we'll call it QUERY2) is identical, except for substituting the tables names where appropriate.
However, when I try to creat a UNION query, like Table QUERY1 UNION Table QUERY2
the calculated field, "LASTNAME", is EMPTY!
I have attempted to use the Nz() function in place of the IIF() statement (it behaves the same way). If I use any other non-calculated field for the ALIAS field "LASTNAME", the full UNION query works fine as well!
Any thoughts as to what might cause such a problem with the ALIAS on a calculated field?
Thanks in advance, Mike
What could it be?
I have read about "Table QUERY1 UNION Table QUERY2" but I've never heard
of anyone actually using it. Maybe I've led a sheltered life, but since
TTBOMK there is not a large body of knowledge about this special form of
the UNION statement, the first thing I would do when faced with an
unexplained problem involving it, is to discontinue its use.
If the Table QUERY1 UNION Table QUERY2 special form of the UNION
statement is golden then what else? Ninety-nine and 44/100 ths per cent
of the query problems that are posted here are syntax problems. I
understand that you are sure there is no problem with your second query.
But to satisfy our curiousity, perhaps you could post it anyway?
Is there something else to grasp at? When a UNION query has field name
differences those of the first query rule. Did you call the calculated
field the same name in both the queries? No, I don't know how this could
affect anything but I'm reaching....
--
Lyle Fairfield mi***@vmsmailingservices.com wrote in
news:11*********************@g44g2000cwa.googlegro ups.com: I have 2 separate queries, which effectively are the same except they draw data from separate tables. Both tables are (design-wise) identical, only the data is different. for each query, there are 2 tables with a standard LEFT JOIN. One field of the query is calculated, looking for a NULL in one table, and then using a field from the second table in that case. One query looks like this:
PARAMETERS [Month] Text ( 255 ); SELECT GR_CUSTOMER.CST_FIRSTNAME, IIf(GR_CUSTOMER!CST_LASTNAME Is Not Null,GR_CUSTOMER!CST_LASTNAME,GR_FAMILY!FAM_FAMILY NAME) AS LASTNAME, GR_CUSTOMER.CST_BIRTHDATE, GR_FAMILY.FAM_ADDRESS1, GR_FAMILY.FAM_ADDRESS2, GR_FAMILY.FAM_CITY, GR_FAMILY.FAM_STATE, GR_FAMILY.FAM_ZIPCODE FROM GR_CUSTOMER INNER JOIN GR_FAMILY ON GR_CUSTOMER.FAMILY_ID = GR_FAMILY.FAMILY_ID WHERE (((MonthName(DatePart("m",[CST_BIRTHDATE]),1))=[Month]));
We'll call this query QUERY1. This query executes PERFECTLY. The second query (we'll call it QUERY2) is identical, except for substituting the tables names where appropriate.
However, when I try to creat a UNION query, like Table QUERY1 UNION Table QUERY2
the calculated field, "LASTNAME", is EMPTY!
I have attempted to use the Nz() function in place of the IIF() statement (it behaves the same way). If I use any other non-calculated field for the ALIAS field "LASTNAME", the full UNION query works fine as well!
Any thoughts as to what might cause such a problem with the ALIAS on a calculated field?
Thanks in advance, Mike
Why are you using bangs(!) instead of dots (.) in the iif
statement?
This may work with the normal query, but fail when trying to
union the two queries.
--
Bob Quintal
PA is y I've altered my email address. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Fred Zuckerman |
last post by:
I have a union query joining two other queries, each with 62 fields.
Interestingly, when I open the query it has the correct number of 2850
records. But if I then set a filter (using filter by...
|
by: Dom Boyce |
last post by:
Hi
First up, I am using MS Access 2002.
I have a database which records analyst rating changes for a list of
companies on a daily basis. Unfortunately, the database has been set
up (by my...
|
by: Richard Holliingsworth |
last post by:
Hello:
Thanks for reading this.
I would like to build a report (Access 2002) that uses SQL queries to
count records in specific groups.
I've tried several methods and so far no luck.
...
|
by: Aaron Haspel |
last post by:
Greetings Access gurus.
I have clients with Access databases in the field that I need to update
-- new tables, new indices, new queries, the works. Since these clients
may have only the Access...
|
by: Susan Bricker |
last post by:
For those of you who have been following my posts - they all pertain to
a Dog Competition Organization's Database.
There are three classes that the dogs can participate:
NOVICE, OPEN, and...
|
by: Alex Satrapa |
last post by:
Is there any (simple? har!) way to optimise a particular SQL query?
At this stage, I'm more interested in making the query more readable, so
I've started hunting down references about relational...
|
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...
|
by: marshmallowww |
last post by:
I have an Access 2000 mde application which uses ADO and pass through
queries to communicate with SQL Server 7, 2000 or 2005.
Some of my customers, especially those with SQL Server 2005, have had...
|
by: CK |
last post by:
How do I write a set based query? I have a groupSets table with fields
setId, idField, datasource, nameField, prefix, active
Data:
1,someIDfield, someTable, someField, pre1, 1
2,someotherIDfield,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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,...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| | |