× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



David

One of the easiest ways to handle this is to use a QM query. You speak of the need to change file name each year. With a QM query you can very easily have a variable for the file name, or any other part of the query statement.

Reading this post will take more time than it takes to do it, perhaps. <g>

First, to put in your filename, you use a constant, or literal. That's easy enough. It'd be the same as the file name in the file list.

So here is the source for a QM query that does this and then gives you all the fields from that file -

SELECT &QT&FILENAME&QT AS MYFILE, &FILENAME.* FROM &FILENAME

Ampersands (&) mark substitution variables. I use &QT for the single quote, since it is otherwise such a bother to work with. The other variable here is &FILENAME.

To create the query, you have a couple options.

1. Run STRQM if you have it, change to the library where the query should go, press F19 (I think - or F17) to change the mode from PROMPT to SQL, take option 1 to create a new query, then enter the statement and save it as you exit.
2. CRTSRCPF QQMQRYSRC RCDLEN(91) in your library and add a member, then put that statement into it. Then run CRTQMQRY against that member.

To run the query, use STRQMQRY. You set the variables there, as in this example-

STRQMQRY YOURQUERY SETVAR(('QT' '''') ('FILENAME' 'FILE2010'))

This ends up running this statement -

SELECT 'FILE2010' AS MYFILE, FILE2010.* FROM &FILE2010

You can create a command with a 10-character parameter for the file name, as a convenient way to run the query. The CPP would be a CL that does the STRQMQRY command.

Very simple, very clean, no embedded SQL, piece of cake, as we say here in the States.

HTH
Vern

David FOXWELL wrote:
Howdy all,


I'm running a complicated query on two tables with UNION all and I'd like the table names to show up in the result to compare them. Is it possible to have the name of the table show up in a select?
I don't want to hard code the name as I must save this query for use in a year's time. The table names change each year.

Thanks.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.