在Management Studio中编辑后,SQL Server视图无法正常工作

时间:2011-09-14 11:15:59

标签: sql-server view ssms

我有一个有效的视图,我在SQL Server Mgmt Studio中编辑它,它没有用,我取出了更改并将其保存下来,尽管将其恢复到原始状态仍然无法正常工作。

我收到了错误

  

无法在包含外部联接的查询中指定已连接的表   运营商。查看或功能'adept_invoiced'包含已连接的表格。

由于视图是在2001年写的,我试图在Management Studio中编辑它(第一次),因此我搜索了一下并提出了一个可能的连接语法问题。

该视图在我今天早上编辑之前已经运行了好几年。

这是From / Where部分....

FROM   dbo.SYS_COMP_ADDRESS
       CROSS JOIN dbo.SL_ACCOUNTS
       INNER JOIN dbo.SL_TRANSACTIONS
                  INNER JOIN dbo.ORD_HEADER
                    ON dbo.SL_TRANSACTIONS.ST_ORDER_NUMBER =
                       dbo.ORD_HEADER.OH_ORDER_NUMBER
                  INNER JOIN dbo.SL_PL_NL_DETAIL
                             LEFT OUTER JOIN dbo.STK_STOCK
                               ON dbo.SL_PL_NL_DETAIL.DET_STOCK_CODE =
                                  dbo.STK_STOCK.STKCODE
                             INNER JOIN dbo.ORD_DETAIL
                               ON dbo.SL_PL_NL_DETAIL.DET_ORDER_LINK =
                                  dbo.ORD_DETAIL.OD_PRIMARY
                             LEFT OUTER JOIN dbo.STK_STOCK3
                               ON dbo.SL_PL_NL_DETAIL.DET_STOCK_CODE =
                                  dbo.STK_STOCK3.STKCODE3
                             LEFT OUTER JOIN dbo.STK_STOCK_2
                               ON dbo.SL_PL_NL_DETAIL.DET_STOCK_CODE =
                                  dbo.STK_STOCK_2.STKCODE2
                             LEFT OUTER JOIN dbo.PRC_PRICE_RECS2
                               ON dbo.SL_PL_NL_DETAIL.DET_PRICE_CODE =
                                  dbo.PRC_PRICE_RECS2.PRCODE2
                    ON dbo.SL_TRANSACTIONS.ST_HEADER_KEY =
                       dbo.SL_PL_NL_DETAIL.DET_HEADER_KEY
         ON dbo.SL_ACCOUNTS.CUCODE = dbo.SL_TRANSACTIONS.ST_COPYCUST
       INNER JOIN dbo.SL_ACCOUNTS2
         ON dbo.SL_ACCOUNTS.CUCODE = dbo.SL_ACCOUNTS2.CUCODE2
WHERE  ( dbo.SL_TRANSACTIONS.ST_TRANTYPE IN ( 'INV', 'CRN' ) )
       AND ( dbo.SL_TRANSACTIONS.ST_BATCH_FLAG <> 1 )
       AND ( dbo.SL_ACCOUNTS.CUCODE <> '1023134' )
       AND ( dbo.SL_ACCOUNTS.CUCODE <> '1023265' )
       AND ( dbo.SL_ACCOUNTS.CUSORT NOT LIKE '%other income%' )
       AND ( dbo.SL_ACCOUNTS.CUSORT NOT LIKE '%supplier%' )  

我不确定它可能会失败的地方,或者如何修复它!

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:0)

您是否在任何地方使用旧样式连接语法,因此在视图定义中搜索*==*

答案 1 :(得分:0)

试试这个:

FROM   dbo.SYS_COMP_ADDRESS 
       CROSS JOIN dbo.SL_ACCOUNTS 
       INNER JOIN dbo.SL_TRANSACTIONS 
                  INNER JOIN dbo.ORD_HEADER 
                    ON dbo.SL_TRANSACTIONS.ST_ORDER_NUMBER = 
                       dbo.ORD_HEADER.OH_ORDER_NUMBER 
                  INNER JOIN dbo.SL_PL_NL_DETAIL
                    ON dbo.SL_TRANSACTIONS.ST_HEADER_KEY = 
                       dbo.SL_PL_NL_DETAIL.DET_HEADER_KEY 
                             LEFT OUTER JOIN dbo.STK_STOCK 
                               ON dbo.SL_PL_NL_DETAIL.DET_STOCK_CODE = 
                                  dbo.STK_STOCK.STKCODE 
                             INNER JOIN dbo.ORD_DETAIL 
                               ON dbo.SL_PL_NL_DETAIL.DET_ORDER_LINK = 
                                  dbo.ORD_DETAIL.OD_PRIMARY 
                             LEFT OUTER JOIN dbo.STK_STOCK3 
                               ON dbo.SL_PL_NL_DETAIL.DET_STOCK_CODE = 
                                  dbo.STK_STOCK3.STKCODE3 
                             LEFT OUTER JOIN dbo.STK_STOCK_2 
                               ON dbo.SL_PL_NL_DETAIL.DET_STOCK_CODE = 
                                  dbo.STK_STOCK_2.STKCODE2 
                             LEFT OUTER JOIN dbo.PRC_PRICE_RECS2 
                               ON dbo.SL_PL_NL_DETAIL.DET_PRICE_CODE = 
                                  dbo.PRC_PRICE_RECS2.PRCODE2 
         ON dbo.SL_ACCOUNTS.CUCODE = dbo.SL_TRANSACTIONS.ST_COPYCUST 
       INNER JOIN dbo.SL_ACCOUNTS2 
         ON dbo.SL_ACCOUNTS.CUCODE = dbo.SL_ACCOUNTS2.CUCODE2 
WHERE  ( dbo.SL_TRANSACTIONS.ST_TRANTYPE IN ( 'INV', 'CRN' ) ) 
       AND ( dbo.SL_TRANSACTIONS.ST_BATCH_FLAG <> 1 ) 
       AND ( dbo.SL_ACCOUNTS.CUCODE <> '1023134' ) 
       AND ( dbo.SL_ACCOUNTS.CUCODE <> '1023265' ) 
       AND ( dbo.SL_ACCOUNTS.CUSORT NOT LIKE '%other income%' ) 
       AND ( dbo.SL_ACCOUNTS.CUSORT NOT LIKE '%supplier%' )