So, there's 2 ways to read this, either we want an "exists" check, or following the SQL, we want a count of all instances. This snippet can be set to do either case based on the existscheck boolean. Ideally though, you would have an index defined, and this could be read much more efficiently than having to scan an entire global
set count=0set existscheck=0//Set to 1 if we only want to find first instanceset targetValue=1329set key = ""for {
set key = $ORDER(^DataTest(key))
quit:key=""if targetvalue = +$LG(^DataTest(key),2) do$INCREMENT(count)
quit:existscheck&&count
}
w !,"Count value is "_count- Log in to post comments