如何替换动态光标以获得更好的性能?

时间:2019-01-31 12:31:49

标签: sql sql-server loops cursor query-optimization

很难找到要在动态查询内循环以替换Cursor的最大值。我想替换动态光标以获得更好的性能。请帮助

set @sql='declare TsmArrray cursor for select * '  
select @sql= CASE when @IncludeAllLangField = 0 then @sql+'from 
IADL_GENDataColumn where otherarray not like '+CHAR(39)+'%.%'+CHAR(39)+' or 
otherarray like '+CHAR(39)+'%.eng'+CHAR(39)+' order by otherarray'  
else @sql+'from IADL_GENDataColumn order by  CASE WHEN otherarray not like 
'+CHAR(39)+'%.%'+CHAR(39)+' or otherarray like '+CHAR(39)+'%.eng'+CHAR(39)+' 
then 1 else 2 end, otherarray' end   
exec (@sql)  

open TsmArrray  
FETCH NEXT FROM TsmArrray into  @colname, @coltyp  
While (@@Fetch_status = 0)  
BEGIN

0 个答案:

没有答案