Re: How can i get the "true" name of an aliased field?
- From: "ekkehard.horner" <ekkehard.horner@xxxxxxxx>
- Date: Thu, 15 Nov 2007 19:15:03 +0100
Bob Barrows [MVP] schrieb:
ekkehard.horner wrote:No, as can easily be seen by adding Bob's test case to aTests. The RegExp'sQuick and dirty example:
Dim aTests : aTests = Array( _
"SELECT FieldName AS FieldNameAlias FROM table" _
, "SELECT [FieldName] AS [FieldNameAlias] FROM table" _
, "SELECT WhatEver.FieldName AS [FieldNameAlias] FROM table" _
, "SELECT F1 AS A1, F2 AS A2 FROM table" _
, "SELECT F1 AS [AS], F2 AS A2 FROM table" _
)
Dim oRE : Set oRE = New Regexp
oRE.Pattern = "\[?(\w+(?:\.\w+)*)\]?\s+AS\s+\[?(\w+)\]?"
oRE.Global = True
oRE.IgnoreCase = True
Dim sTest, oMTS, oMT
For Each sTest In aTests
WScript.Echo "------", sTest
Set oMTS = oRE.Execute( sTest )
For Each oMT In oMTS
WScript.Echo "", oMT.SubMatches( 1 ), "==>",
oMT.SubMatches( 0 ) Next
Next
Does this handle this case:
Select ([Field1] & [Field2]) AS FieldAlias
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.
.
- Follow-Ups:
- 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?
- 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]
- 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: How can i get the "true" name of an aliased field?
- Previous by thread: Re: How can i get the "true" name of an aliased field?
- Next by thread: Re: How can i get the "true" name of an aliased field?
- Index(es):
Relevant Pages
|
|