Why does a CTE in SQL Server execute the INNER JOIN when no conditions are met? -


i have table mse have rows statusid = 1. in query inner joined view executed regardless of value of column statusid. how prevent it?

with cte201401291517  (     select       'quantityoutpershift' = sum([vsqo].[quantityoutpershift])       , [mse].[shiftgroup]       , [mse].[station]       , [vsqo].[shift]          [dbo].[mse] mse    inner join        [dbo].[vmsqo] vsqo on [mse].[station] = [vsqo].[fromstation]                             , ( [mse].[shiftgroup] = [vsqo].[shiftgroup]                                   or [mse].[shiftgroup] = 'all') -- order important!          [mse].[statusid] = 3    group       [mse].[shiftgroup]       , [mse].[station]       , [vsqo].[shift]) update   [dbo].[mse] set    [dbo].[mse].[quantityoutpershift] = [cte].[quantityoutpershift]   , [dbo].[mse].[shiftcurrent] = [cte].[shift]   --output inserted.*    cte201401291517 cte    [dbo].[mse].[station] = [cte].[station]    , ( [dbo].[mse].[shiftgroup] = [cte].[shiftgroup]          or [dbo].[mse].[shiftgroup] = 'all' )  -- order important!    , [dbo].[mse].[statusid] = 3; 

i can't without cte because of fact i'm updating table sum cannot used in update statement.

i'm using sql server 2005


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -