%SELECTALL
If you ever need to create a view that selects all fields from a particular record, then you should be using the %SelectAll meta-sql construct.
Why? Because %SelectAll uses the underlying record definition to select the fields - so it will always return all fields from the underlying record, even if that record definition changes.
The basic syntax is:
- %SelectAll(RECORD_NAME ALIAS)
There is all a %SelectDistinct construct which adds a distinct to the select clause and uses the same syntax.
%SelectAll returns all the fields for the record specified and includes a from clause.
For example, say I want the latest effective dated, active fields from PSXLATITEM. My SQL might start something like this:
Instead of typing out all those fields, lets use %SelectAll - that's what I did to generate this example btw ;)
So our meta-sql would look like this - (I've also replaced sysdate with %CurrentDateIn)
Note that %SelectAll wraps date, time and date/time fields with %DateOut, %TimeOut, %DateTimeOut as well. This resolves into the following meta-sql:
Note that the example includes an alias of A in the parameters to %SelectAll. If you are using %SelectAll you might have to play with your SQL a bit to get it work, especially if you are using joins to other tables. It may not work in all cases, but if nothing else, its a time saver!