Question
· 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
Discussion (4)2
Log in or sign up to continue

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.StatementMetadata
    set meta = result.%GetMetadata()
    write meta.columns.GetAt(1).ODBCType ;fetch first field
}