How to use the @@IDENTITY when I use INSERT SELECT ?
DECLARE @ENTITYID AS BIGINT
INSERT INTO Quiz_QuizQuestion
SELECT @ENTITYID,
@DIFICULTLEVELCODE,
ENTITYID,
@QuizEntityId,
Title,
[Description],
[Description],
Duration
FROM Education_Question
WHERE EntityID = 1 --THIS SELECT RETURN JUST 1 RECORD
SET @ENTITYID = @@IDENTITY
SELECT @ENTITYID // NULL
You need not insert @@IDENTITY into the table in your scenario – you have to CREATE table with IDENTITY field like this: