INSERT语句不能包含将值赋给变量的SELECT语句

时间:2013-09-17 10:59:01

标签: sql-server-2008

    DECLARE  @TopicsFilterFranchiseId INT 

 DECLARE @tblTopics AS table    
 (    
  ClientCategoryID int,    
  CategoryID int,    
  ProductID int    
 )   


     INSERT INTO @tblTopics 
     SELECT  @TopicsFilterFranchiseId = ID from dbo.GetIDsTableFromIDsList(@FranchiseID)
    while @TopicsFilterFranchiseId is not null
       begin
         EXEC SBS_G_GetTopicsByFranchiseID @TopicsFilterFranchiseId  
         Set @TopicsFilterFranchiseId = NULL 
       end

我收到此错误请告诉我如何解决此错误

1 个答案:

答案 0 :(得分:1)

INSERT INTO @tblTopics 
SELECT  @TopicsFilterFranchiseId = ID from dbo.GetIDsTableFromIDsList(@FranchiseID)

以上代码无效。

而是具有要插入值/列的select语句。

E.g

INSERT INTO @tblTopics 
SELECT  @ClientCategoryID,@CategoryId,@Productid 

在insert语句之前为变量赋值,不能将值赋值给变量并在同一语句中插入表中。

相关问题