1

我创建了一个视图,而不是在一个存储过程中我想将它与一个表连接起来,但是我遇到了错误:

对过程“vw_Security”的请求失败,因为“vw_Security”是一个视图对象。

这是我的 sp :

BEGIN

  -- declare the tables we will use
  DECLARE @Temp_Order TABLE
  (
    order_id  decimal,
    TRADE_PLACE_ID  decimal,
  )

  DECLARE @Temp_Pos TABLE
  (
    Fund_Type varchar(max),
    Desk_Ticker varchar(max),
  )

  DECLARE @Temp_Tick TABLE
  (
    SyCode varchar(max),
    Group_Name varchar(max)
  )

  INSERT INTO @Temp_Order
  EXEC LNK_xxxx @fromDate = '02/26/2013' ,
          @ToDate  = null, 
          @Trader = '' , 
          @Accts = @fundname    

  INSERT INTO @Temp_Pos
  EXEC LNK_Txxxxxx

  INSERT INTO @Temp_Pos
  EXEC LNK_xxxxx

  ;WITH CTE AS 
  ( 
    SELECT DISTINCT Ticker,CREATE_DATE,COMMENTS,EXEC,POS.Weighted_Avg_Price 
    from @Temp_Order TOR
    LEFT JOIN @Temp_Pos POS ON TOR.TICKER = POS.Desk_Ticker
  )
  SELECT Group_Name 
  From LNK_xxxxxx.dbo.vw_Security 
END
4

1 回答 1

0

您没有在现有查询中加入您的视图。您需要使用JOIN语法将视图与CTE

;WITH CTE AS 
( 
  SELECT DISTINCT Ticker,CREATE_DATE,COMMENTS,EXEC,POS.Weighted_Avg_Price 
  from @Temp_Order TOR
  LEFT JOIN @Temp_Pos POS 
    ON TOR.TICKER = POS.Desk_Ticker
)
SELECT s.Group_Name 
From LNK_xxxxxx.dbo.vw_Security s
JOIN CTE c
  on s.someCol = c.someCol  -- replace the someCol with your columns for joining
于 2013-02-27T10:51:39.883 回答