Question Prashant Singhal · Jul 26, 2023

I want to Fetch columnType for sql query

Hii all,
I'm trying to fetch columnType from resultSet of type %Library.ProcedureContext.
Executed the class query by %Execute after %PrepareClassQuery.

Product version: IRIS 2023.1

Comments

Ashok Kumar T  Sep 8, 2023 to Prashant Singhal

Hi Prashant,

You can get the values from%Metadata.columns.GetAt(i).ODBCType the ODBC type is referred the  datatype of the column. 12 for VARCHAR refer the ODBC type integer and datatype here

ClassMethod GetColumnType() As%String
{
    set statement = ##class(%SQL.Statement).%New()
    set tSC = statement.%PrepareClassQuery("Sample.Person","TestQuery")
    set result = statement.%Execute()
    #dim meta As%SQL.StatementMetadataset meta = result.%GetMetadata()
    write meta.columns.GetAt(1).ODBCType ;fetch first field
}
0