我想提高此更新查询的性能,因为它需要花费大量时间才能执行:
Qry = "update tab1 set cDate=GetDate() where right('000000000000'+in_num,12)='"
& InvNo.PadLeft(12, "0") & "' and (Total-Amount)<>Balance and cDate is null"
答案 0 :(得分:1)
为什么强制填充in_num
和InvNo
以及前导0:
right('000000000000'+in_num,12) = InvNo.PadLeft(12, "0")
这将阻止使用in_num
上的任何索引。
答案 1 :(得分:0)
您没有提到您正在使用哪个数据库,但如果它支持计算列,那么您可以通过为填充行创建计算列来提高查询速度,然后可以创建索引。
当然,这是假设您不能使用简单的整数类型作为发票号。如果您可以原样使用in_no,那么请确保您在该列上有索引。