SQL-Server: Incorrect syntax near the keyword 'with'. If this statement is a common table expression

前端 未结 4 1483
一向
一向 2021-02-20 17:39
create table #temp
(
  pName Varchar(20),
  DateBegin DateTime,
  DateEnd DateTime
)

Insert Into #temp(pName, DateBegin, DateEnd)
Values(\'Player1\', \'01/04/2012\', \'         


        
4条回答
  •  清酒与你
    2021-02-20 18:26

    Try this syntax:

    CREATE TABLE [dbo].[CIQTempJointMembersLink](   
        [JointMembersID] [int] NULL,
        [fk_CIQPerson_PersonID] [int] NULL)
    
    GO
    
    WITH Summary AS (
        SELECT p.[JointMembersID], 
               p.[fk_CIQPerson_PersonID],            
               p.[JointMembersLinkID],
               ROW_NUMBER() OVER(PARTITION BY [fk_CIQPerson_PersonID] 
                                     ORDER BY [fk_CIQPerson_PersonID] DESC) AS rownumber
          FROM [CIQRegos].[dbo].[CIQJointMembersLink] p)
    
    INSERT INTO [CIQTempJointMembersLink]([JointMembersID], [fk_CIQPerson_PersonID])
    
    SELECT JointMembersLink.[JointMembersID], JointMembersLink.[fk_CIQPerson_PersonID]
    FROM Summary JointMembersLink
    WHERE JointMembersLink.rownumber = 1 and JointMembersLink.[fk_CIQPerson_PersonID] is NOT NULL
    Order by JointMembersLink.JointMembersLinkID;
    
    
    
    Drop Table [dbo].[CIQTempJointMembersLink]
    

提交回复
热议问题