473,657 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL for field names from a table

Hi,

We have a database with some tables with (what I would
denote as) 'referred field names'.
Like this:
DataTable1 with fields F1, F2, F3
DataTable2 with fields F3, F4, F5
DataTable3 with fields F1, F5, F2

We also have a table with field names
FieldNameTable with fields FIELD, NAME
containing data like:
FIELD NAME
----------------
F1 FieldName1
F2 FieldName2
F3 FieldName3
F4 FieldName4
F5 FieldName5

Now, we need a way to query the data of these tables, but
the result of the query should show the 'referred field names'
from the FieldNameTable.

For example, querying DataTable3 should produce the output
FieldName1 FieldName5 FieldName2
------------------------------------------
... ... ...
... ... ...

Any idea how (and whether) this can be done with an SQL query?
Thanks in advance for tips & tricks.

Dirk Vdm
Oct 6 '05 #1
6 2006
You would have to use dynamic SQL to do that - try and avoid it if you can.
Why not use a view to alias the column names instead of putting them in a
table?

--
David Portas
SQL Server MVP
--

"Dirk Van de moortel" <di************ **@ThankS-NO-SperM.hotmail.c om> wrote
in message news:y%******** ************@ph obos.telenet-ops.be...
Hi,

We have a database with some tables with (what I would
denote as) 'referred field names'.
Like this:
DataTable1 with fields F1, F2, F3
DataTable2 with fields F3, F4, F5
DataTable3 with fields F1, F5, F2

We also have a table with field names
FieldNameTable with fields FIELD, NAME
containing data like:
FIELD NAME
----------------
F1 FieldName1
F2 FieldName2
F3 FieldName3
F4 FieldName4
F5 FieldName5

Now, we need a way to query the data of these tables, but
the result of the query should show the 'referred field names'
from the FieldNameTable.

For example, querying DataTable3 should produce the output
FieldName1 FieldName5 FieldName2
------------------------------------------
... ... ...
... ... ...

Any idea how (and whether) this can be done with an SQL query?
Thanks in advance for tips & tricks.

Dirk Vdm

Oct 6 '05 #2

"David Portas" <RE************ *************** *@acm.org> wrote in message news:lO******** ************@gi ganews.com...
You would have to use dynamic SQL to do that - try and avoid it if you can.
Why not use a view to alias the column names instead of putting them in a
table?

--
David Portas
SQL Server MVP
--


Ah yes, of course. A few views will do the job just fine.
Thanks.

Dirk Vdm

Oct 7 '05 #3
Let's get back to the basics of an RDBMS. Rows are not records; fields
are not columns; tables are not files. Then you are mixing data and
metadata in complete violation of the basic princi-les of data
modeling.

What are you trying to do??? If you do not get a valid design, you
will wind up with dynamic SQL, procedural code, IDENTITY columns and
all kinds of other non-SQL nightmares.

Oct 8 '05 #4

"--CELKO--" <jc*******@eart hlink.net> wrote in message news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
Let's get back to the basics of an RDBMS. Rows are not records; fields
are not columns; tables are not files. Then you are mixing data and
metadata in complete violation of the basic princi-les of data
modeling.
I'm not mixing data and metadata. Someone else did.

What are you trying to do???
Trying to make the best of someone else's mess without
interfering ;-)
If you do not get a valid design, you
will wind up with dynamic SQL, procedural code, IDENTITY columns and
all kinds of other non-SQL nightmares.


I know.
I will pass the message. In fact I alread have, but they
don't care.

Dirk Vdm
Oct 8 '05 #5
Sorry about that. Have you updated your resume yet? It is always best
to start looking before the company fails ...

Oct 8 '05 #6

"--CELKO--" <jc*******@eart hlink.net> wrote in message news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
Sorry about that.
No problem.
Have you updated your resume yet? It is always best
to start looking before the company fails ...


It's not the company I work for, and... I don't think it will
ultimately fail over this particular incovenience. If/when it fails,
we'll probably end up using another company's solution
(probably our own), and I'm sure it will have its own little
inconveniences ;-)

Cheers,
Dirk Vdm
Oct 9 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3911
by: Earl Anderson | last post by:
I have imported an Excel worksheet into A97/WinXPH which had the new employees names in one field ( in a Last Name,First Name configuration). I wanted to split that one field ( ) into two fields ( & ). The table I imported, , contains 61 records with a PK of . Using the Query Grid, I constructed the following query (SQL View here) to split into the two fields I wanted and place the results into a new table called : SELECT...
3
18511
by: Tom | last post by:
Data is collected over time in an Excel worksheet with 20 columns. The Excel worksheet starts out as a copy of a template as is filled in as data is collected. Eventually the worksheet file is saved and an Access table is linked to the Excel worksheet. Different people collect the data in the Excel worksheet than who use the database. The fields in the table are the labels in the first row of the worksheet which is what I want. The...
3
3020
by: Michael | last post by:
Hi everyone, I am trying to change the field names for a table that is being exported via Excel. Its a spreadsheet that our National Office sends us but even after promise after promise they keep changing the field names which makes it nearly impossible to run any pre-generated queries etc. The solution really is to get someone to check the field names before importing the spreadsheet but I want to do it in code. I have written
1
3428
by: Don Leverton | last post by:
Hi Folks, I have been given a CD with approx 130 .xls files (bean-counters!) that I would like to import and merge to ONE table (tblTradeshow). The XL files are *similarly*, but not identically structured, and the first row does NOT contain field names. Some (actually most) of the column names *are* the same in all of the spreadsheets.
6
1744
by: HD | last post by:
Hello. For the following, I would appreciate if anyone could tell me: if it can be done, how it might done, and/or what search terms I could use to find the solution myself. I would like to create a database in which _adding a new record automatically creates a new field in the table_ (ideally, deleting a record would also delete the field that was created when that record was added). Thus, the number of fields in the table would...
18
18359
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on a remote update of tables and fields and can't find enough information on these things. Also, how do you index a field in code?
9
3109
by: sellcraig | last post by:
Microsoft access 2 tables table "data main" contains a field called "code" table "ddw1" is created from a make table query of "data main" Goal- the data in "code" field in needs to be inserted into a standard web address in the table (the filed name is link) in ddw1 Example address ---
4
22532
by: Bob | last post by:
Hi all, I've got a table that I've imported and it has junk at the top of the table, so after import I run a delete query to remove the junk lines then I'm left with the field names I want for the table at the top of the table but the field names currently are 'field1' etc, so how do I rename the field names to the fields on the top row of the table. Cheers,
4
1604
by: | last post by:
Given an XML file (dataset.writexml), here is my output (simplified for this posting): <?xml version="1.0" standalone="yes"?> <NewDataSet> <Category> <CategoryId>80</CategoryId> <Category>MyCat</Category> </Category> </NewDataSet>
4
2894
by: justice750 | last post by:
Hi All, I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field is not a null value. I am not using any code behind (C#) to bind the data or manipulate the data. I have read that when there is a null value in the database that there is no record in the "dataset". Can anyone show me how to bind a value in the...
0
8413
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
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,...
0
8842
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, 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...
1
8513
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,...
0
8617
tracyyun
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...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.