SQL Server cursor left join
<p>I'm working on a view with many select statements and calculations in the background. </p>

<p>One cursor query is causing a problem and I don't where to start to fix this problem.</p>

<p>The SQL statement below is working fine. I added <code>WAn_AnzTage</code> which is stored in <code>TWorkflowAntraege</code> and <code>@_wananztage</code> for fetching the next value. These two additions are now commented out from the script. Once I add those to the script, I get no return values anymore.</p>

<p>However, when I run the script as SQL query itself outside of the cursor with fixed values everything is working fine.</p>

<pre><code>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 &gt;= @_date and WPo_DatumBis &lt;= @5)
             OR (WPo_DatumVon &lt; @_date and WPo_DatumBis &gt;= @_date)
             OR (WPo_DatumVon &lt; @5 and WPo_DatumBis &gt;= @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
</code></pre>