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

Lookup table IDs as Columns

I'm trying to mail merge a single record in MS Word. That works. The problem is that single record or row in Access can't be created via SQL alone. I can see how to use vba to get from where I'm at to where I'm going, but I don't want to use vba.

It seems to me that since combo boxes are so normal, writing this query should be normal as well.

Expand|Select|Wrap|Line Numbers
  1. PATIENT    PATIENT TELEPHONE      TELEPHONE TYPE
  2. PatientID  PatientTelephoneID     TelephoneTypeID
  3.            TelephoneNumber        Description
  4.            TelephoneType
  5.            PatientID
  6.  
  7. TelephoneTypeID Description
  8. 1               Office
  9. 2               Home
  10. 3               Fax
  11. 4               Cell
  12.  
  13.  
I wrote an insert query for each type, so I have four queries using the following SQL:

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO PrintPatientTelephones ( PatientTelephoneID, PatientID, TelephoneTypeID, Office )
  2. SELECT PatientTelephone.PatientTelephoneID, PatientTelephone.PatientID, PatientTelephone.PatientTelephoneType, PatientTelephone.TelephoneNumber
  3. FROM Patient INNER JOIN PatientTelephone ON Patient.PatientID = PatientTelephone.PatientID
  4. GROUP BY PatientTelephone.PatientTelephoneID, PatientTelephone.PatientID, PatientTelephone.PatientTelephoneType, PatientTelephone.TelephoneNumber, PatientTelephone.PatientTelephoneType
  5. HAVING (((PatientTelephone.PatientID)=[Forms]![frmProcessPatientReferral].[txt67]) AND ((PatientTelephone.PatientTelephoneType)=2))
  6. ORDER BY PatientTelephone.PatientID;
I change the bolded ID number, as appropriate for each query.

This generates several rows. The telphone number appears below the appropriate telephone type column heading.


I need to generate a single row for each patient, instead of several rows.
Dec 4 '13 #1

✓ answered by zmbd

Save you some time and grief with CTQ take a read thru:
•Crosstab query techniques - row totals, zeros, parameters, column headings All versions (allenbrowne.com)
This information has kept me sane (ok, almost sane) when trying to work with these. The wizard is "OK" for setting the simple CTQ, and is often where I start; however, it lacks a great deal as you'll find reading AB site. There are other sites and examples out there too.

If you get stuck, post back with the SQL for your query (please format it using the [CODE/] button) and one of us should be along shortly to help. Rabbit is one of the masters of SQL (IMHO) and has done things I've not thought possible - all without VBA!

6 1928
zmbd
5,501 Expert Mod 4TB
You've complete lost me here.... and that's a rare thing.

If a single record mail-merges correctly, then all should. It should not matter what the query it self looks like.

I do not understand what you are attempting with an insert query...

However, if you want your table that looks like this:

Expand|Select|Wrap|Line Numbers
  1. [pk][fk][field][info]
  2. 1,   2,   a,    info1
  3. 2,   2,   b,    info2
  4. etc...
to look like this
Expand|Select|Wrap|Line Numbers
  1. [fk][info1][info2]
  2. 1    x      y 
  3. 2    a      b
within Access then the only easy way might be a crosstab query.
Dec 4 '13 #2
I think you understand what I need given your last two examples. A crosstab query would still need some vba. I'll look at it again. Thanks.
Dec 5 '13 #3
zmbd
5,501 Expert Mod 4TB
Save you some time and grief with CTQ take a read thru:
•Crosstab query techniques - row totals, zeros, parameters, column headings All versions (allenbrowne.com)
This information has kept me sane (ok, almost sane) when trying to work with these. The wizard is "OK" for setting the simple CTQ, and is often where I start; however, it lacks a great deal as you'll find reading AB site. There are other sites and examples out there too.

If you get stuck, post back with the SQL for your query (please format it using the [CODE/] button) and one of us should be along shortly to help. Rabbit is one of the masters of SQL (IMHO) and has done things I've not thought possible - all without VBA!
Dec 5 '13 #4
Thanks for the crosstab mention and reference. I had tried one, but didn't do a good job on it. I looked at the article you referenced. Then I Googled it and found, http://www.youtube.com/watch?v=k_uLJK3mT2o, which did exactly what I needed.

It couldn't have been as hard as what I was doing or what I had tried earlier. And, yes, no vba. Great!
Dec 5 '13 #5
zmbd
5,501 Expert Mod 4TB
Hurray!
Glad this got you on the correct track.
It would be helpful to have the SQL available for those of us that can not get at the youtube site...
Dec 5 '13 #6
So here is my SQL

Expand|Select|Wrap|Line Numbers
  1. TRANSFORM First(PatientTelephone.TelephoneNumber) AS FirstOfTelephoneNumber
  2. SELECT PatientTelephone.PatientID
  3. FROM PatientTelephone
  4. GROUP BY PatientTelephone.PatientID
  5. ORDER BY PatientTelephone.PatientID
  6. PIVOT PatientTelephone.PatientTelephoneType;
  7.  
Skip using the wizard. Write the usual query then convert it to a crosstab query select the row field and column fields in Design View; Change you data field to First instead of Group By; and you're done.

It does exactly what I needed. This after three weeks of trying this and that.
Dec 5 '13 #7

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

Similar topics

1
by: Big Dave | last post by:
Good morning. This group has been a great help so far, and it is much appreciated. Here's my new question. I want to be able to create a datagrid at runtime, which will have template columns...
1
by: James | last post by:
I am used to VB6 but need to develop something in .Net. I need to create several bound combo-boxes which will use lookup tables to get their values. I created a form using the dataform wizard....
3
by: dbuchanan | last post by:
Hello, (Windows forms - SQL Server) I fill my datagrid with a stored procedure that includes relationships to lookup tables so that users can see the values of the combobox selections rather...
1
by: Dave | last post by:
I have several comboboxes on a form that are bound to the same dataset. I want to simulate the Access Lookup Table in these comboboxes. That is, I can select a value loaded in the combobox without...
11
by: Paul H | last post by:
Suppose I have a table called tblPeople and I want a field to illustrate whether each person prefers cats or dogs. I could do it one of three ways. 1. A plain text field Create a text field in...
5
by: sensreview | last post by:
Hello, I need help in selecting a value from combo list thru one lookup table and update different table on MS access form. For eg; I have a lookup table of usernames, I need to use this...
5
by: Andrus | last post by:
I'm creating a database Winforms application using VCS Express 2005 I have some large lookup tables (may be up to 500000 records) which contains name and id and are stored in sql server. I...
3
by: Markw | last post by:
I think this was recently asked but I was a little lost on the example that was used so I'm reasking it with an example I can understand. Also forgive me for such a basic question but I really am...
1
by: tellercb | last post by:
Hello everyone! I'm new here, so go easy on me ;-) I have a pretty good skillset with VBA for Excel, but now I'm venturing out into Access. So if the solution I'm looking for requires VBA (and I'm...
0
by: =?Utf-8?B?RU1hbm5pbmc=?= | last post by:
(I originally posted this to the data access newsgroup but received no replies) I've got an Access 2003 mdb that I'm converting to VB.Net. I'm having trouble with getting the main data source to...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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
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 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.