User bio
404 bio not found
Malaga, Spain
Member since Feb 21, 2018
Posts:
Replies:
Also... you can create a ClassMethod to pass the fields to retrieve
ClassMethod DynamicQuery(columns As %String) As %Status
{
// columns: comma-separated string, e.g. "Book,Author"
// Basic validation
If columns = "" {
Write "No columns specified.", !
Quit $$$ERROR
}
// Build the SQL query
Set sql = "SELECT " _ columns _ " FROM myTables.Books"
Try {
Set stmt = ##class(%SQL.Statement).%New()
Set sc = stmt.%Prepare(sql)
If $$$ISERR(sc) {
Write "Error preparing the query.", !
Quit sc
}
Set rset = stmt.%Execute()
While rset.%Next() {
For i = 1:1:rset.%ColumnCount {
Write rset.%GetColumnName(i), ": ", rset.%Get(i), " | "
}
Write !
}
} Catch ex {
Write "Error executing the query: ", ex.DisplayString(), !
Quit ex.AsStatus()
}
Quit $$$OK
}
Then, call it using this command:
Do ##class(MyApp.Utils).DynamicQuery("Book,Author")
Hi @Touggourt
If you want to retrieve the values, prepare the query by concatenating the values you want to retrieve
set var1 = "Book"
set var2 = "Author"
set query = "SELECT "_var1_","_var2_" FROM myTables.Books"
set statement = ##class(%SQL.Statement).%New()
set status = statement.%Prepare(query)
set rset = statement.%Execute()
do rset.%Display()
Have a look the following link:
https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cls...
Regards
Open Exchange applications:
Certifications & Credly badges:






Global Masters badges:







Followers:
Following:
Hi community: