Database Wildcards
Greetings,
How do I organize a wildcard search with respect to a database search?
Example of what I am trying to do: s x=$o(^G("ABC","A*",x))
Trying to navigate through the ^G global for all occurrences of "ABC", and "A*" ("A"+wildcard) but I am new to M and don't know positively how to do this. Perhaps I don't use an "*" at all, rather; another convention altogether.
Please advise.
Thanks in advance for everyone's assistance.
Discussion (2)0
Comments
- Take a look at the source code of the queries ##class(%Global).[Find/Get()]
- Pattern Matching
Hi Russel,
I would solve the problem along the following lines...
set k2=$s($d(^G("ABC","A")):"A",1:$o(^G("ABC","A")))while $e(k2,1)="A" {
set k3=$o(^G("ABC",k2,""))
while k3'="" {
write !,k2," ",k3
set k3=$o(^G("ABC",k2,k3))
}
set k2=$o(^G("ABC",k2))}Explanation...
//set k2 to either "A" if that key exists in the data, or the next key following "A".set k2=$s($d(^G("ABC","A")):"A",1:$o(^G("ABC","A")))//only process k2 when it starts with an "A", this is the wildcard functionality you are looking for//when k2 does not start with an "A" the logic will drop throughwhile $e(k2,1)="A" {
//get first child key of k2
set k3=$o(^G("ABC",k2,""))
//loop on all child keys found
while k3'="" {
write !,k2," ",k3
//get next child key of k2
set k3=$o(^G("ABC",k2,k3))
}
//get the next k2 key
set k2=$o(^G("ABC",k2))}