sql 使用%ResultSet.SQL对象查询结果。写在Intersystems缓存对象脚本中。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 使用%ResultSet.SQL对象查询结果。写在Intersystems缓存对象脚本中。相关的知识,希望对你有一定的参考价值。

ResultSetSample()
	// Build query string
	Set sql = "Select Value, DateTimeStamp From Spectrum_Support_Metrics.EnsPerformanceMetricsData Where " _
				"CheckType = 'datasize' AND " _
				"Detail = '/ensemble/mgr/PROD/' AND " _
				"DateTimeStamp > '201012170930'"
	
	// Create new resultSet object to work with called "rs".  It's basically a cursor.
	// This %Prepare command executes the query contained in "sql", sets the result to "rs", and gives an "error" flag back.
	Set rs = ##class(%ResultSet.SQL).%Prepare(sql,.error,"")
	
	// Check to see that the query executed without error.
	If $IsObject(error) {
		// In here is where you do something if you get an error.
		Write "Error = " _ error
		Quit 0
	}
	
	// Lets use a While statement to loop over each row returned from the query.
	// The %Next command on the result set loads in the first row, and parses over the rest.
	While (rs.%Next()) {
		
		// Use the %Get command to get the value of the column specified, in this case, "Value".
		Write "Value = " _ rs.%Get("Value") _ " at " _ rs.%Get("DateTimeStamp") _ " date/time.", !

	}

以上是关于sql 使用%ResultSet.SQL对象查询结果。写在Intersystems缓存对象脚本中。的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 Entity Framework Core 5.0 将复杂 SQL 查询的结果行映射到自定义 DTO?

如何将 SQL 查询结果行作为具有不同标题名称的列? [关闭]

如何在全范围内平均减少 SQL 查询的结果行?

SQL Server 查询以计算每日“持仓”未结订单

Hibernate 查询sql结果行数的几种方法

怎样用sqlserver将查询结果行转列