Question
· Jan 22, 2019

Embedded SQL How to return a lIst of data

I have this query That I am trying  to use in my class when testing on the terminal I expect to get the results printed on the terminal but I am only getting zero printed please can anyone out there advice on what I am doing wrong

Method PatientInfo(ID As %String) As %Status
{ #dim status as %Status=$$$OK
  SET myquery="SELECT GUID, IDType,IDValue FROM MergeHyland.TypeTwoDimesionCollection WHERE GUID ="_ID
  SET rset=##class(%ResultSet.SQL).%Prepare(myquery,.err,"")
    WHILE rset.%Next() {
    WRITE !,rset.GUID & ":" & rset.IDType& ":" & rset.IDValue
    }
  WRITE "End of data"
    return status
}
Discussion (1)1
Log in or sign up to continue

My guess is that you are concatenating string with the operator "&" (AND) instead of "_".

If you do so, ObjectScript will cast your string as boolean false, the result of (false and false and false) equals 0, the result you see in your question.

Method PatientInfo(ID As %String) As %Status#dim status as %Status=$$$OK
  SET myquery="SELECT GUID, IDType,IDValue FROM MergeHyland.TypeTwoDimesionCollection WHERE GUID ="_ID
  SET rset=##class(%ResultSet.SQL).%Prepare(myquery,.err,"")
    WHILE rset.%Next() {
    WRITE !,rset.GUID _ ":" _ rset.IDType_ ":" _ rset.IDValue
    }
  WRITE "End of data"
    return status
}