Re: How can i get the "true" name of an aliased field?
- From: "Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx>
- Date: Thu, 15 Nov 2007 14:01:06 -0500
ekkehard.horner wrote:
No, as can easily be seen by adding Bob's test case to aTests. The
Does this handle this case:
Select ([Field1] & [Field2]) AS FieldAlias
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.
.
- References:
- How can i get the "true" name of an aliased field?
- From: Patrick
- Re: How can i get the "true" name of an aliased field?
- From: Bob Barrows [MVP]
- Re: How can i get the "true" name of an aliased field?
- From: ekkehard.horner
- Re: How can i get the "true" name of an aliased field?
- From: Bob Barrows [MVP]
- Re: How can i get the "true" name of an aliased field?
- From: ekkehard.horner
- How can i get the "true" name of an aliased field?
- Prev by Date: Re: How can i get the "true" name of an aliased field?
- Next by Date: Re: Error => -2147467259 Could not save; currently locked by ano
- Previous by thread: Re: How can i get the "true" name of an aliased field?
- Next by thread: How can i get the new vaule of a counter field?
- Index(es):
Relevant Pages
|
|