Can you try to run the SQL query (in SQL Management Studio or other tool). What is the result? Use specific Neighbor IP instead of ${NeighborIP}
SELECT NodeName=CASE (SELECT COUNT(*) FROM Nodes WHERE IP_Address='${NeighborIP}')
WHEN 0 THEN '${NeighborIP}'
ELSE (SELECT DISTINCT Caption FROM Nodes WHERE IP_Address='${NeighborIP}')
END