我正在处理一个在后台有很多select语句和计算的视图。
一个游标查询导致问题,我不知道从哪里开始解决此问题。
下面的SQL语句工作正常。我添加了WAn_AnzTage
,TWorkflowAntraege
存储在@_wananztage
和declare cur cursor for
select
WPo_DatumVon, WPo_DatumBis, WPo_AbwArt, WPo_AbwTag --, WAn_AnzTage
from
TWorkflowAntraege
inner join
TWorkflowPool on WAn_AntragsNr = WPo_AntragsNr
inner join
TAbwArt on Abw_AbwArt = WPo_AbwArt
where
wan_persnr = @3
and (Wan_WorkflowStatus = 0 or WAn_WorkflowStatus = 4)
and Wan_Antragsart = 2
and WPo_AbwArt like @_likeabw
and ((WPo_DatumVon >= @_date and WPo_DatumBis <= @5)
OR (WPo_DatumVon < @_date and WPo_DatumBis >= @_date)
OR (WPo_DatumVon < @5 and WPo_DatumBis >= @5))
and WPo_AbwArt like @_likeabw
open cur
fetch next from cur
into @_datumvon, @_datumbis, @_abwart, @_abwtag --, @_wananztage
while (@@FETCH_STATUS = 0)
begin
-- something something
-- not touching WAn_AnzTage yet.
end
close cur
deallocate cur
中,用于获取下一个值。现在,这两个新增内容已从脚本中注释掉。一旦我将它们添加到脚本中,我就不再获得返回值了。
但是,当我使用固定值将游标作为SQL查询本身运行在游标之外时,一切正常。
IndexOf(input) > -1
答案 0 :(得分:0)
试试这样。
首先将记录插入临时表,然后使用临时表中的记录。
CREATE TABLE #temp_TWorkflowAntraege (
WPo_DatumVon NVARCHAR(10)
,WPo_DatumBis NVARCHAR(10)
,WPo_AbwArt NVARCHAR(10)
,WPo_AbwTag NVARCHAR(10)
)
insert into #temp_TWorkflowAntraege
SELECT WPo_DatumVon
,WPo_DatumBis
,WPo_AbwArt
,WPo_AbwTag --, WAn_AnzTage
FROM TWorkflowAntraege
INNER JOIN TWorkflowPool ON WAn_AntragsNr = WPo_AntragsNr
INNER JOIN TAbwArt ON Abw_AbwArt = WPo_AbwArt
WHERE wan_persnr = @3
AND (Wan_WorkflowStatus = 0 OR WAn_WorkflowStatus = 4)
AND Wan_Antragsart = 2
AND WPo_AbwArt LIKE @_likeabw
AND ((WPo_DatumVon >= @_date
AND WPo_DatumBis <= @5) OR (WPo_DatumVon < @_date AND WPo_DatumBis >= @_date) OR (WPo_DatumVon < @5 AND WPo_DatumBis >= @5))
AND WPo_AbwArt LIKE @_likeabw
DECLARE cur CURSOR
FOR
SELECT WPo_DatumVon
,WPo_DatumBis
,WPo_AbwArt
,WPo_AbwTag
FROM #temp_TWorkflowAntraege
OPEN cur
FETCH NEXT
FROM cur
INTO @_datumvon
,@_datumbis
,@_abwart
,@_abwtag --, @_wananztage
WHILE (@@FETCH_STATUS = 0)
BEGIN
-- something something
-- not toching WAn_AnzTage yet.
END
CLOSE cur
DEALLOCATE cur
答案 1 :(得分:0)
尝试将Declare语句更新为:
Declare cur Cursor Local Fast_Forward For
这可以防止生成光标时出现任何类型的锁定或延迟。