Connecting Tech Pros Worldwide Help | Site Map

Convert nickname to fullname when querying data

Member
 
Join Date: May 2007
Posts: 37
#1: May 23 '07
I have a table of providers that has a license number and fullname field, among others. Deman helped me with being able to enter a nickname and having it change to the fullname if a nickname exists in a nickname table when I have new entries. I also have a table called TA where I enter requests, linking to the providers table with the license number. (The fullname field exists only in the providers table.) I'd like to be able to query the TA table for requests by entering the nickname (as it exists in the nickname table) rather than entering the fullname. Can anyone help? Thanks in advance.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,703
#2: May 25 '07

re: Convert nickname to fullname when querying data


You should be able to do this in a query after linking the tables in the relevant way. Your question is not currently clear enough to provide a direct answer.
If you post the table Meta-Data we can probably get you further with this.
Here is an example of how to post table MetaData :
Table Name=tblStudent
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. StudentID; AutoNumber; PK
  3. Family; String; FK
  4. Name; String
  5. University; String; FK
  6. Mark; Numeric
  7. LastAttendance; Date/Time
You will need to post (in this format please) for all the tables that link the data you need together.
Member
 
Join Date: May 2007
Posts: 37
#3: May 25 '07

re: Convert nickname to fullname when querying data


I'm sorry, I'm pretty much a novice. I'm not sure I understand about Meta-data. Is this it?

I have three tables, by the way:

Table Name=[Licensed Providers]
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. License No;Text;PK
  3. Admin Agency;Text
  4. and some other fields
Table Name = Nicknames
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. Nickname;Text;PK
  3. Admin Agency;Text
  4. these are the only two fields
Table Name = TA
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. License No;Text (this is the same as the Providers table)
  3. and some other fields.
I've created several entries in the nicknames table where I have a short abbreviation in the nickname field and then the full name in the Admin Agency field. For example, doe for the nickname and Department of Education for the Admin Agency field.

When I enter a new Licensed Provider, I can either enter the full name in the Admin Agency field or an abbreviation (or nickname) and if an entry exists for that nickname in the nicknames table it will change that entry to the full name, or leave it as typed if one doesn't exist. I'd like to be able to use this same thing in a query.

My query has both the Providers table and TA table, linked by the license number field. I can enter a part of the Admin Agency name (such as dep or edu) and it will look up records where the Department of Education is the Admin Agency. I would like to be able to enter either a part of the Admin Agency name or the nickname as it exists in the nickname table and find records. If it would be easier to have an extra field in the query that would be OK. I'll know ahead of time whether I want to look up by partial name or nickname, so if it would be easier to do with two separate queries, that would be fine.

Does that make more sense? Thanks so much. I really appreciate the help.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,703
#4: May 25 '07

re: Convert nickname to fullname when querying data


It does (sort of) make sense.
My confusion now is how you're typing in a search string. You talk of running a (presumably SELECT) query, but there's no mention of a form or other such method of filtering or searching.
The SQL can be created for linking in the NickName stuff, but I'd need a better understanding of what you're doing with it to know what to suggest.
A good start would be to post the SQL of your current query. Please DO use the [code] tags (#) provided. It saves me the job of adding them for you afterwards ;)
Member
 
Join Date: May 2007
Posts: 37
#5: May 25 '07

re: Convert nickname to fullname when querying data


Here's my query code: ( I hope this is what you mean by code tags)

Expand|Select|Wrap|Line Numbers
  1. SELECT TA.[License No],
  2.        [Licensed Providers].[Admin Agency],
  3.        TA.[Type TA],
  4.        TA.Consultant,
  5.        TA.[Date Received],
  6.        TA.[Date to RC],
  7.        TA.[Date Assigned],
  8.        TA.[Reason 1],
  9.        TA.[Reason 2],
  10.        TA.[Date Scheduled],
  11.        TA.[Date Completed],
  12.        TA.[Requested By CCLS],
  13.        TA.[Sent to CCLS],
  14.        TA.Comments
  15. FROM [Licensed Providers] INNER JOIN TA
  16.   ON [Licensed Providers].[License No] = TA.[License No]
  17. WHERE ((([Licensed Providers].[Admin Agency]) Like "*" & [Enter Partial Admin Agency Name] & "*")
  18.   AND  ((TA.[Date Completed]) Is Null));
I've got a form that is attached to the query.

I'm opening the form, which in turn starts the query which asks me to enter a partial agency name. When I do that, the records are displayed in the form. Thanks for helping me. I realize I'm terribly inadequate in providing the information in the proper form.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,703
#6: May 25 '07

re: Convert nickname to fullname when querying data


To add [code] tags to your post, simply select all the text that is code, then click on the graphic above the message you're typing, which looks like a hash (#). This will put [code] tags around the selected text for you. I fixed your last post for you, don't worry.

I will have to look at your question again later in the weekend as it's after 23:00 here atm and I'm getting tired.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,703
#7: May 26 '07

re: Convert nickname to fullname when querying data


First lets deal with tidying up some things to make life easier for ourselves.
I've simplified usage of the [Licensed Providers] table with a pseudonym LP. This makes it easier to work with and understand at a glance. I assume that your table MetaData is the incorrect version and that the actual name of the [Providers] table is [Licensed Providers]. I've edited your post to reflect this.
I've changed the strings to use the more correct quote (') within SQL.
Expand|Select|Wrap|Line Numbers
  1. SELECT TA.[License No],
  2.        LP.[Admin Agency],
  3.        TA.[Type TA],
  4.        TA.Consultant,
  5.        TA.[Date Received],
  6.        TA.[Date to RC],
  7.        TA.[Date Assigned],
  8.        TA.[Reason 1],
  9.        TA.[Reason 2],
  10.        TA.[Date Scheduled],
  11.        TA.[Date Completed],
  12.        TA.[Requested By CCLS],
  13.        TA.[Sent to CCLS],
  14.        TA.Comments
  15. FROM ([Licensed Providers] AS LP
  16.      INNER JOIN TA
  17.   ON LP.[License No]=TA.[License No])
  18.      INNER JOIN NickNames AS NN
  19.   ON LP.[Admin Agency]=NN.[Admin Agency]
  20. WHERE ((TA.[Date Completed]) Is Null)
  21.   AND  ((LP.[Admin Agency] Like '*' & [Enter Partial Admin Agency Name (or NickName)] & '*')
  22.    OR   (NN.Nickname Like '*' & [Enter Partial Admin Agency Name (or NickName)] & '*'));
Now to the changes more relevant to your particular issue :
First of all you need to link in the extra table (See the FROM clause).
Now you need to change the WHERE clause to include a check for the Nickname. This should be ORed with the other name check, but together these checks should be ANDed with the date check.

I have made the assumption here that all [Admin Agency]s have associated Nicknames. If that is not true then this will not work as expected and some further changes will be required.
Member
 
Join Date: May 2007
Posts: 37
#8: May 29 '07

re: Convert nickname to fullname when querying data


Thanks so very much for your help. The Admin Agencies do not all have nicknames. Nicknames only exist for some of the longer ones or the ones most frequently used.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,703
#9: May 29 '07

re: Convert nickname to fullname when querying data


Quote:

Originally Posted by CindySue

Thanks so very much for your help. The Admin Agencies do not all have nicknames. Nicknames only exist for some of the longer ones or the ones most frequently used.

OK, but I'll have to come back to this tomorrow (or later today if I'm lucky).
If I haven't replied by tomorrow morning, then bumb the thread to re-add it to my list for tomorrow.
For future reference, that would have been handy to know before-hand ;)
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,703
#10: May 30 '07

re: Convert nickname to fullname when querying data


Quote:

Originally Posted by CindySue

Thanks so very much for your help. The Admin Agencies do not all have nicknames. Nicknames only exist for some of the longer ones or the ones most frequently used.

The JOIN is changed and the Nz() function is used to handle unwanted Nulls.
Expand|Select|Wrap|Line Numbers
  1. SELECT TA.[License No],
  2.        LP.[Admin Agency],
  3.        TA.[Type TA],
  4.        TA.Consultant,
  5.        TA.[Date Received],
  6.        TA.[Date to RC],
  7.        TA.[Date Assigned],
  8.        TA.[Reason 1],
  9.        TA.[Reason 2],
  10.        TA.[Date Scheduled],
  11.        TA.[Date Completed],
  12.        TA.[Requested By CCLS],
  13.        TA.[Sent to CCLS],
  14.        TA.Comments
  15. FROM ([Licensed Providers] AS LP
  16.      INNER JOIN TA
  17.   ON LP.[License No]=TA.[License No])
  18.      LEFT JOIN NickNames AS NN
  19.   ON LP.[Admin Agency]=NN.[Admin Agency]
  20. WHERE ((TA.[Date Completed]) Is Null)
  21.   AND  ((LP.[Admin Agency] Like '*' & [Enter Partial Admin Agency Name (or NickName)] & '*')
  22.    OR   (Nz(NN.Nickname,'') Like '*' & [Enter Partial Admin Agency Name (or NickName)] & '*'));
Member
 
Join Date: May 2007
Posts: 37
#11: May 30 '07

re: Convert nickname to fullname when querying data


I'm terriby sorry, but I'm not getting any results from the query. I copied the query info and pasted it into SQL view. I copied the Licensed Providers and Nicknames tables and named them LP and NN so the names would be the same. In LP I deleted all but 6 records. In TA I deleted all but 10 entries, using each license number from the LP table once and one four times. I used Dept. of Education as the Admin Agency in the LP table, and it exists exactly the same (I copied and pasted to be sure) in the NN table, with doe as the nickname. When I query I can't get any results at all, either from a nickname or from a partial name.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,703
#12: May 30 '07

re: Convert nickname to fullname when querying data


The table names I used were the ones you provided. The query simply uses aliases, that's all. The SQL code was designed to copy and paste straight into a QueryDef's SQL view.
What do you mean you copied the tables?
What do you have in the way of tables now?
Member
 
Join Date: May 2007
Posts: 37
#13: May 30 '07

re: Convert nickname to fullname when querying data


I didn't understand about the aliases, so since I didn't have tables with those names I copied the Licensed Providers table and named it LP and copied the Nicknames table and called it NN. I also complicated things when I didn't make sure the date completed field was null in my practice data. I put their names back and made sure the date completed field is empty, and it seems to be working now. I REALLY appreciate all your patience and effort. Thank you so very much.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,703
#14: May 30 '07

re: Convert nickname to fullname when querying data


Not a problem :) I'm glad it worked when you 'reverted'.
Wherever you see the keyword AS in SQL it indicates that the preceeding expression is to be named as the succeeding name.
Tables can get this treatment, but so can fields and more complicated expressions (including sub-queries, but let's not go there for now :D). It can also be written by simply forgetting the AS keyword, but It's my practice never to do that, as it's more confusing to read and understand.
Reply


Similar Microsoft Access / VBA bytes