Hi,
How do you bind the output columns from a UNION query when the fields from
the two tables have different names? Consider this query (WHERE clauses
omitted)...
SELECT SurnameBirth, FNameBirth, DOB, 'Birth' from tblBirth UNION
SELECT SurnameAlias, FNameAlias, #1/1/100#, 'Alias' from tblAlias;
What I am doing here is searching two tables for a person where the name
given may be the person's original name (at birth) or subsequent changed
name (marriage, etc). There are four fields to be returned from each table
with corresponding data types. The tblAlias does not have DOB so I am
returning a dummy literal value that will be recognised by code. In
addition, the fourth field is another literal that identifies the source of
the data row ("Birth" or "Alias"). The search criteria have been omitted
for simplicity.
I am trying to display the columns returned in text boxes in a listing in
Continuous Mode. The form displaying this data is called by another form
which does the query to produce a public recordset which is then used to set
the Recordset property of the listing form via the Load event.
Because the field names are different, depending on the source of the row, I
have tried to bind the columns to the controls using the generic syntax
"rst.Fields (n)" in an expression. While this syntax is accepted, it results
in a display of "#Name" in each text box.
I have found by trial and error that if I set "tblBirth" as the
RecordSource, I can then bind the controls using the field names from this
table, and it works even with rows returned from tblAlias including the
dummy DOB value. The only problem now is how to display the literal values
"Birth" and "Alias" as neither corresponds to a column in tblAlias.
Sorry for the lengthy post, but my questions really are:
1) Can you bind data to controls using "rst.Fields (n)" syntax somehow?
2) If not, how can you bind a dummy column which doesn't have a field name?
One solution to 2) might be to use VBA as in (eg):
if rst.Fields(4) = "Birth" then
'set text box to "Birth"
else
'set text box to "Alias"
end if
This would have to be done for every row returned.
As a final question, is it possible in SQL to return the table name itself
as a "column"? If so, I wouldn't need to use the literal to identify the
source table.
TIA.
--
Cheers,
Lyn. 2 2743
Use the AS keyword to alias the field names so they are consistent between
the two tables, e.g.:
SELECT SurnameBirth, FNameBirth, DOB, 'Birth' AS Source
FROM tblBirth
UNION ALL
SELECT SurnameAlias, FNameAlias, Null AS DOB, 'Alias' AS Source
FROM tblAlias;
--
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.
"Lyn" <lh******@ihug. com.au> wrote in message
news:d2******** **@lust.ihug.co .nz... Hi, How do you bind the output columns from a UNION query when the fields from the two tables have different names? Consider this query (WHERE clauses omitted)...
SELECT SurnameBirth, FNameBirth, DOB, 'Birth' from tblBirth UNION SELECT SurnameAlias, FNameAlias, #1/1/100#, 'Alias' from tblAlias;
What I am doing here is searching two tables for a person where the name given may be the person's original name (at birth) or subsequent changed name (marriage, etc). There are four fields to be returned from each table with corresponding data types. The tblAlias does not have DOB so I am returning a dummy literal value that will be recognised by code. In addition, the fourth field is another literal that identifies the source of the data row ("Birth" or "Alias"). The search criteria have been omitted for simplicity.
I am trying to display the columns returned in text boxes in a listing in Continuous Mode. The form displaying this data is called by another form which does the query to produce a public recordset which is then used to set the Recordset property of the listing form via the Load event.
Because the field names are different, depending on the source of the row, I have tried to bind the columns to the controls using the generic syntax "rst.Fields (n)" in an expression. While this syntax is accepted, it results in a display of "#Name" in each text box.
I have found by trial and error that if I set "tblBirth" as the RecordSource, I can then bind the controls using the field names from this table, and it works even with rows returned from tblAlias including the dummy DOB value. The only problem now is how to display the literal values "Birth" and "Alias" as neither corresponds to a column in tblAlias.
Sorry for the lengthy post, but my questions really are: 1) Can you bind data to controls using "rst.Fields (n)" syntax somehow? 2) If not, how can you bind a dummy column which doesn't have a field name?
One solution to 2) might be to use VBA as in (eg):
if rst.Fields(4) = "Birth" then 'set text box to "Birth" else 'set text box to "Alias" end if
This would have to be done for every row returned.
As a final question, is it possible in SQL to return the table name itself as a "column"? If so, I wouldn't need to use the literal to identify the source table.
TIA.
-- Cheers, Lyn.
Allen,
Many thanks. That worked just as I wanted!
--
Cheers,
Lyn.
"Allen Browne" <Al*********@Se eSig.Invalid> wrote in message
news:42******** *************** @per-qv1-newsreader-01.iinet.net.au ... Use the AS keyword to alias the field names so they are consistent between the two tables, e.g.:
SELECT SurnameBirth, FNameBirth, DOB, 'Birth' AS Source FROM tblBirth UNION ALL SELECT SurnameAlias, FNameAlias, Null AS DOB, 'Alias' AS Source FROM tblAlias;
-- 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. "Lyn" <lh******@ihug. com.au> wrote in message news:d2******** **@lust.ihug.co .nz... Hi, How do you bind the output columns from a UNION query when the fields from the two tables have different names? Consider this query (WHERE clauses omitted)...
SELECT SurnameBirth, FNameBirth, DOB, 'Birth' from tblBirth UNION SELECT SurnameAlias, FNameAlias, #1/1/100#, 'Alias' from tblAlias;
What I am doing here is searching two tables for a person where the name given may be the person's original name (at birth) or subsequent changed name (marriage, etc). There are four fields to be returned from each table with corresponding data types. The tblAlias does not have DOB so I am returning a dummy literal value that will be recognised by code. In addition, the fourth field is another literal that identifies the source of the data row ("Birth" or "Alias"). The search criteria have been omitted for simplicity.
I am trying to display the columns returned in text boxes in a listing in Continuous Mode. The form displaying this data is called by another form which does the query to produce a public recordset which is then used to set the Recordset property of the listing form via the Load event.
Because the field names are different, depending on the source of the row, I have tried to bind the columns to the controls using the generic syntax "rst.Fields (n)" in an expression. While this syntax is accepted, it results in a display of "#Name" in each text box.
I have found by trial and error that if I set "tblBirth" as the RecordSource, I can then bind the controls using the field names from this table, and it works even with rows returned from tblAlias including the dummy DOB value. The only problem now is how to display the literal values "Birth" and "Alias" as neither corresponds to a column in tblAlias.
Sorry for the lengthy post, but my questions really are: 1) Can you bind data to controls using "rst.Fields (n)" syntax somehow? 2) If not, how can you bind a dummy column which doesn't have a field name?
One solution to 2) might be to use VBA as in (eg):
if rst.Fields(4) = "Birth" then 'set text box to "Birth" else 'set text box to "Alias" end if
This would have to be done for every row returned.
As a final question, is it possible in SQL to return the table name itself as a "column"? If so, I wouldn't need to use the literal to identify the source table.
TIA.
-- Cheers, Lyn.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Alan |
last post by:
I'm just about to start a project that needs to combine the results of a SQL
Server query with the results of an Index Server query. The basic idea is
that the user enters/selects a bunch of search criteria on a form. Most of
the criteria selected by the user will be used to select records from the
database - standard WHERE clause stuff - but the user can also enter
free-text that should be searched for in associated uploaded documents. The...
|
by: Matt O'Donnell |
last post by:
Does anyone know how I can 'join' the results of
one SQL query to the bottom of another?
Eg. I have two queries:
1. SELECT Name, Surname FROM People WHERE Surname = Smith
NAME SURNAME
|
by: JD Kronicz |
last post by:
Hi .. I have an issue I have been beating my head against
the wall on for some time. I am trying to use late
binding for MS graph so that my end users don't have to
worry about having the right version of the MS Graph type
library. Up until now I have been walking them through
the process of setting the references to include their
version of MS Graph library.
My problem is that I can not seem to get the syntax
correct .. or perhaps...
|
by: axlchris |
last post by:
Is it possible to bind two different tables to a listbox, or do I have to iterate through the result using the datareader and manually add each item in the listbox?
thanks
---
Posted using Wimdows.net NntpNews Component - Posted from .NET's Largest Community Website: http://www.dotnetjunkies.com/newsgroups/
|
by: Ryan Ternier |
last post by:
Don't ask why it's coded this way.. the clueless developer before me
coded things upside down and insideout :\
Anyways,
We have a simple SQL Query that reads a table into a DataSet.
Here's the way the query is being built:
strSQL = "SELECT FirstName + ' ' + LastName as TextField, UserID AS
| |
by: vivekian |
last post by:
Hi ,
I need to place the results of two different queries in the same result
table parallel to each other.
So if the result of the first query is
1 12
2 34
3 45
|
by: |
last post by:
I have a question about spawning and displaying subordinate list controls
within a list control. I'm also interested in feedback about the design of
my search application. Lots of code is at the end of this message, but I
will start with an overview of the problem.
I've made a content management solution for my work with a decently
structured relational database system. The CMS stores articles. The CMS also
stores related items --...
|
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 designed to show the expiring contracts.
To do this I use a straight forward query in my form's ON LOAD code
strwhere = " BETWEEN #" & Now() & "# AND #" &
DateAdd("m", 6, Now()) & "#"
Set MyQueryDef = MyDatabase.CreateQueryDef("qryMattersQuery",...
|
by: Ken Fine |
last post by:
I have set up Microsoft Search Server 2008 Express.
I want to know how I can query against it and return results in a form that
can be bound to ASP.NET controls like ListViews. If there's simply a way to
return results as an ArrayList or other data structure I can figure out the
rest of this problem myself.
What I don't want:
* I don't want to deal with XSLT
* I don't want to work with prebuilt controls from SharePoint or somesuch. I
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |