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
Hii all,
I'm trying to fetch columnType from resultSet of type %Library.ProcedureContext.
Executed the class query by %Execute after %PrepareClassQuery.
1. Get the NextResult() resultset
2. Get the Metadata from the resultset
How to get the column type from Metadata ?
Hi @Prashant Singhal ! Please, read this interesting article to get the data type from a query:
https://community.intersystems.com/post/sql-statement-metadata
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 }