Below are working SQL commands to extract the latest value for a DCI. Note - the DCI as named for the node is queried not its ID
The following SQL will list all of the idata_value’s for the DCI named 'SQL Cache Memory KB' for node 201
SELECT TOP 1 items.item_id, items.node_id, idata_201.idata_timestamp, idata_201.idata_value
FROM items INNER JOIN
idata_201 ON items.item_id = idata_201.item_id
WHERE (items.description = 'SQL Cache Memory KB') AND (items.node_id = 201)
ORDER BY idata_201.idata_value DESC, idata_201.idata_timestamp ASC
The following SQL code will list the latest idata_value for the DCI named 'SQL Cache Memory KB' for node 201
select A.item_id,A.ts,D.idata_value,I.description from
(
select item_id,max(idata_timestamp) as ts from idata_201 group by item_id
) A
join idata_201 AS D on A.item_id=D.item_id and D.idata_timestamp = A.ts
join items AS I on I.item_id = A.item_id
where description = 'SQL Cache Memory KB'