create table #temp
(
pName Varchar(20),
DateBegin DateTime,
DateEnd DateTime
)
Insert Into #temp(pName, DateBegin, DateEnd)
Values(\'Player1\', \'01/04/2012\', \'
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]