缩短后续sql查询的时间,这需要1到2个小时

时间:2015-02-03 06:49:38

标签: sql-server

Update table1 set BD_COL=ltrim(rtrim(MAT_DRG) from table1  inner join table2 on
(([name] like '24_%' and Substring([name],4,len([name])=ltrim(rtrim(MAT_DRG)) and isnull(MAT_DRG,'') and itemtype='STD') 
or
([name] like '24/%' and Substring([name],4,len([name])=ltrim(rtrim(MAT_DRG)) and isnull(MAT_DRG,'') and itemtype='STD')
or
([name] like '24_%' and Substring([name],7,16)=ltrim(rtrim(MAT_DRG)) and  itemtype='STD')
or ltrim(rtrim(MAT_DRG))=[name])
)

1 个答案:

答案 0 :(得分:0)

Substring([name],4,len([name])=ltrim(rtrim(MAT_DRG))这样的表达会损害性能,甚至会在名称列上创建索引。考虑将计算列创建为SubString(name, 4, len(name))并在此新列上创建索引。

对其他表达式和列执行相同的操作。