Database query during a "fetch"
Posted: Fri Nov 09, 2012 3:49 am
by dagfinnrime
Hi,
The Query-capabilities to databases are very nice. I would like to use those in a fetch-command as well. I have tried a few alternatives that don't work (and I have read the query-part in the manual, and the fetch-command in Command-reference).
Yes, I realize I can do a loop checking @ifirst of every series and deleting/keeping based on that, but I thought it would be very nice to using the query-part of Eviews in stead.
I use Eviews 7.2.
Thanks in advance,
Dagfinn
Re: Database query during a "fetch"
Posted: Fri Nov 09, 2012 8:33 am
by EViews Gareth
Use the (not yet documented) @wquery function.
Code: Select all
@wquery can be used to obtain a list of all objects inside a database that meet one or more search criteria.
The function format is
string @wquery(dbname[, where_expression [, field_list]])
where all three arguments are strings. The return argument is also a string which uses space delimiters to separate items (which is compatible with the EViews for loop and other @wxxx functions).
The arguments are as follows:
- dbpath is the alias/filename/path of the database
- where_expression is a string containing the criteria to search for where the string is in the same format as specified in the Advanced Queries section of the database documentation. If the where expression is omitted, all objects in the database are considered to match the criteria.
- field_list is a comma delimited list of the fields to return for each object that matches the ‘where’ expression. The list of possible fields is documented in the Advanced Queries section of the database documentation. If field_list is omitted, the name of each object that satisfies the ‘where’ expression is returned.
EXAMPLES:
%matnames = @wquery(“mydb”, “type=matrix”)
Set %matnames equal to a space delimited list of the names of all matrix objects in the database ‘mydb’
string s =@wquery(“mydb”, “freq=q and start<1950”)
set s equal to a space delimited list of the names of all objects in the database ‘mydb’ which have a quarterly frequency and have data starting before 1950
%freqs = @wunique(@wquery(“mydb”, “”, “freq”))
set %freqs equal to a space delimited list containing a list of the frequencies used in the database ‘mydb’
%end = @wquery(“mydb”, “name=myseries”, end”) returns the end date of the series myseries in the database “mydb”
Re: Database query during a "fetch"
Posted: Fri Nov 09, 2012 12:33 pm
by dagfinnrime
Thanks,
I like to do the following:
Code: Select all
%db_list=@wquery("db_daily",""name matches "of* or vol*" and start<1/1/2004"")
But it doesn't work. The following work:
Code: Select all
string teststr =@wquery("db_daily","name matches of* and start<1/1/2004")
The "name matches "ofd2* or vold2*" and start<1/1/2004" part work in the advanced query box of the database.
Thanks in advance,
Dagfinn
Re: Database query during a "fetch"
Posted: Sat Nov 10, 2012 5:07 am
by dagfinnrime
The following works:
Code: Select all
%db_list=@wquery("db_daily","name matches of* or name matches vol* and start<1/1/2004")
fetch(d=DB_daily) {%db_list}