需要找到 id 的最大值,通过这个值我需要读取其他列的值。但它受另一种列类型的影响。我使用了这个 sql 命令:
"SELECT * FROM Table WHERE id = (SELECT MAX(id) FROM Table WHERE type = 1)"
ID 列是 bigint 类型,类型是 nchar。我也尝试将它与 type = '1' 一起使用,但同样的问题。错误在“id =”部分之后
谢谢您的回复
编辑:
SqlCeCommand com = new SqlCeCommand();
if (LocalType == '1') { com = new SqlCeCommand("SELECT req_id FROM Requisition WHERE id = (SELECT MAX(id) FROM Requisition WHERE type = 1)", con); }
else if (LocalType == '2') { com = new SqlCeCommand("SELECT req_id FROM Requisition WHERE id = (SELECT MAX(b.id) FROM Requisition AS b WHERE b.type <> 1)", con); }
using (com)
{
SqlCeDataReader reader = com.ExecuteReader();
}