I have the Order By PracID in the query (dbo.EmisPracExtract)
SELECT TOP (100) PERCENT OrganisationGuidDigest AS PracGuidDigest, NationalPracticeCode AS NPC,
PracID
FROM EMISNov15DB.dbo.PracIDMatchList WITH (tablock)
ORDER BY PracID
My issue was primarily that some PRACIDs have values and some NULL - the one's with values to be inserted as it is however if it is a NULL then pick the Max value in the table lets say in the example above its 2002, then do the incremental value to the NULL values i.e., 20003, 20004 etc
Will this work, will it retain the PracID that already exists and populate the other records with a continuation i.e., 20003, 20004 in the above example...
INSERT TOP 100 PERCENT INTO dbo.EmisPractice ( PracGuidDigest, NPC, PracID )
SELECT PracGuidDigest, NPC, PracID
FROM dbo.EmisPracExtract
ORDER BY PracID
SET IDENTITY_INSERT dbo.EmisPractice1 ON
INSERT INTO dbo.EmisPractice1 ( PracID, PracGuidDigest, NPC)
SELECT PracID, PracGuidDigest, NPC
FROM dbo.EmisPracExtract
ORDER BY PracID
SET IDENTITY_INSERT dbo.EmisPractice1 OFF
I received the error message as shown;
Msg 515, Level 16, State 2, Line 3 Cannot insert the value NULL into column 'PracID', table 'EMISRESNvMaster.dbo.EmisPractice1'; column does not allow nulls. INSERT fails. The statement has been terminated.
SET IDENTITY_INSERT dbo.EmisPractice1 ON
INSERT INTO dbo.EmisPractice1 ( PracID, PracGuidDigest, NPC)
SELECT PracID, PracGuidDigest, NPC
FROM dbo.EmisPracExtract
WHERE PracID IS NOT NULL
ORDER BY PracID
SET IDENTITY_INSERT dbo.EmisPractice1 OFF
INSERT INTO dbo.EmisPractice1 ( PracGuidDigest, NPC)
SELECT PracGuidDigest, NPC
FROM dbo.EmisPracExtract
WHERE PracID IS NULL
ORDER BY PracGuidDigest