Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Odd text being added to the end of a Union query - Access 2013 1

Status
Not open for further replies.

MattGreer

Technical User
Feb 19, 2004
471
US
The following text is being added to the end of a union query that is working just fine. I entered the SQL without this, and when I go to look at the SQL statement after this is added:

SQL:
  AS [%$##@_Alias];

Can someone explain what this is and why it's there?


Thanks!!


Matt
 
Seems like you wrote your union query as a subquery without alias and msaccess adds a default alias.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I guess... You say I wrote it as a subquery. Should I have written it that way? Basically I took the one query that worked, and then duplicated it, edited it as needed, and managed to stitch it together so I got no errors, and it appears to work just fine.

There's the query in original form:

SQL:
INSERT INTO tblRunData
SELECT * FROM (
SELECT tblImport.DateTime AS [TimeStamp], tblInstruments.InstrumentID AS InstrumentID, tblImport.Gas AS FieldValue
FROM tblImport, tblTypes INNER JOIN (tblInstruments INNER JOIN tblLocations ON tblInstruments.InstrumentID = tblLocations.InstrumentID) ON tblTypes.TypeID = tblInstruments.TypeID
WHERE (((tblImport.Gas) Is Not Null) AND ((tblInstruments.InstName)=[tblImport].[TransmitterID]) AND ((tblTypes.Type)="Pressure") AND ((tblLocations.LocName)="Gathering"))
UNION ALL
SELECT tblImport.DateTime AS [TimeStamp], tblInstruments.InstrumentID AS InstrumentID, tblImport.Fluid AS FieldValue
FROM tblImport, tblTypes INNER JOIN (tblInstruments INNER JOIN tblLocations ON tblInstruments.InstrumentID = tblLocations.InstrumentID) ON tblTypes.TypeID = tblInstruments.TypeID
WHERE (((tblImport.Fluid) Is Not Null) AND ((tblInstruments.InstName)=[tblImport].[TransmitterID]) AND ((tblTypes.Type)="Liq_P") AND ((tblLocations.LocName)="Gathering"))
);

Is there anything "bad" with it? Anything I could improve?

Thanks!!


Matt
 
INSERT INTO tblRunData
SELECT * FROM (
SELECT tblImport.DateTime AS [TimeStamp], tblInstruments.InstrumentID AS InstrumentID, tblImport.Gas AS FieldValue
FROM tblImport, tblTypes INNER JOIN (tblInstruments INNER JOIN tblLocations ON tblInstruments.InstrumentID = tblLocations.InstrumentID) ON tblTypes.TypeID = tblInstruments.TypeID
WHERE (((tblImport.Gas) Is Not Null) AND ((tblInstruments.InstName)=[tblImport].[TransmitterID]) AND ((tblTypes.Type)="Pressure") AND ((tblLocations.LocName)="Gathering"))
UNION ALL
SELECT tblImport.DateTime AS [TimeStamp], tblInstruments.InstrumentID AS InstrumentID, tblImport.Fluid AS FieldValue
FROM tblImport, tblTypes INNER JOIN (tblInstruments INNER JOIN tblLocations ON tblInstruments.InstrumentID = tblLocations.InstrumentID) ON tblTypes.TypeID = tblInstruments.TypeID
WHERE (((tblImport.Fluid) Is Not Null) AND ((tblInstruments.InstName)=[tblImport].[TransmitterID]) AND ((tblTypes.Type)="Liq_P") AND ((tblLocations.LocName)="Gathering"))
) [!]AS U[/!];

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top