Re: How can i get the "true" name of an aliased field?



ekkehard.horner wrote:

Does this handle this case:
Select ([Field1] & [Field2]) AS FieldAlias

No, as can easily be seen by adding Bob's test case to aTests. The
RegExp's pattern uses "list of words separated by ." to find the real
fieldname(s). If you want to match arbitrary expressions before the
AS, you can't use RegExps, because they aren't meant for bracketed
(hierarchical) structures. Maybe you can use "SELECT", ",", and "AS"
to cut the expression(s) from the SQL statement, but then you risk
nasty cases like "(LName & ', ' & FName)".

So my q&d example works for easy cases; some additional work could
make it suitable for a restricted format - you could use "(( " and "
))" to bracket the names/expressions you are interested in - but
there comes the point where it would be more sensible to
collect/store the real names/expression before you build/execute the
statement. Another - definitely not quick - strategy: write a parser
for (the relevant subset of) SQL.

I was thinking of something more like this:

dim sSQL, sSelect, ar, dictFields, i, arField, sSource, sAlias
' for testing - in actual code one would use sSQL=rs.Source
sSQL="SELECT Surname & ' ' & Name AS Operator, " & _
"Phone, City, State FROM People"
ar=Split(sSQL," FROM ")
sSelect=ar(0)
sSelect=LTrim(Mid(sSelect,7))
ar=Split(sSelect,",")
Set dictFields=createobject("scripting.dictionary")
for i = 0 to ubound(ar)
arField=Split(ar(i)," AS ")
sSource = trim(arField(0))
if ubound(arField) = 1 then
sAlias = trim(arField(1))
else
sAlias = trim(arField(0))
end if
dictFields.Add sAlias,sSource
next
MsgBox "The source of Operator is: " & dictFields("Operator")

Again, it requires the developer to be strict about using all-caps for
the SQL keywords (SELECT AS FROM)

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


.



Relevant Pages

  • Re: Problems with SQL MSDE after SBS SP1 upgrade!
    ... Thanks for updates. ... This newsgroup only focuses on SBS technical issues. ... | Subject: Re: Problems with SQL MSDE after SBS SP1 upgrade! ...
    (microsoft.public.windows.server.sbs)
  • RE: NOLOCK due to data movement
    ... It is unfortunate that you do not understand that this is an SBS problem. ... The default instance of SQL 2005 is working fine. ... Please understanding our newsgroup is mainly focused on SBS support. ... Microsoft CSS Online Newsgroup Support ...
    (microsoft.public.windows.server.sbs)
  • Re: Outputs into Word
    ... To get a sql output in word without using mail merge, write a batch file to spool the sql to a temp location on the users c:\ then get the spool file from the temp location to open in word. ... no need for a data source just basic logic. ... One last coment if I may though, I would like thank Cindy again for spending her time trying to resolve my query and also like to show my appreciation for my new found "newsgroup ethiquette". ...
    (microsoft.public.word.docmanagement)
  • RE: Moving an SBS SharePoint Database
    ... Actually this is a SQL issue which should be better handled in our SQL ... Newsgroup. ... Move Databases Between Computers That Are Running SQL Server ... This newsgroup only focuses on SBS technical issues. ...
    (microsoft.public.windows.server.sbs)
  • RE: Help please
    ... you can allow access to SQL for user in Windows 2003 domain. ... > newsgroup, as there you may have more good sharing in SQL fields. ... > Microsoft CSS Online Newsgroup Support ... > | At this moment my client use software without license (please don't ask ...
    (microsoft.public.windows.server.sbs)