This is a general question when it comes to querying data in a table. I have a specific example though to illustrate my question.
Within my database is a table that contains employee information, e.g.: UserID, Name, Job Title, etc.
This is an import of the company LDAP directory, thus the table is called tblLDAP. By default, certain fields in LDAP contain additional hierarchal information such as the Organization Unit (ou), etc.
One specific field in the table is called "manager". When importing LDAP, it comes through like this:
uid=jdoe, ou=People, o=MyCompany, c=US
However, all I truly want is the portion that immediatelly follows "uid="- which would simply be "jdoe" in this example.
One approach is to run an update query after the LDAP data is imported into the table, e.g.:
Code:
UPDATE tblLDAP SET tblLDAP.manager = Mid([manager],5,(InStr(1,[Manager],","))-5);
This uses the "MID" function to essentially extract the UID substring and updates the "manager" field for every record in the table (over 10,000) accordingly
But I could also create a SELECT query and use that same "MID" function as an expression, e.g.:
Code:
SELECT tblLDAP.uid, Mid([manager],5,(InStr(1,[Manager],","))-5) AS Manager_UID
FROM tblLDAP;
This would still show the intended substring without actually updating the data in the source table (tblLDAP).
So I guess my question is, is there a "right" or "wrong" way to do it - specifically from an overall performance standpoint? The end result is the same, though obviously with the second approach, it precludes me from needing to run an "UPDATE" query upon importing the data into tblLDAP. This query only takes a few seconds to run even for all 10,000+ records, but perhaps it would still make more sense to use an expression to show the data in the intended way versus actually taking the step to update it in the table?
This field, as well as several others in tblLDAP, is pulled over in many other 'SELECT' queries (and related reports) in the database, so it seems like there would have to be a preferred way of doing it.. but perhaps it's 6-to-1 half dozen to the other and I'm simply overthinking it!