これを試してみてください -
USE [Grading]
INSERT INTO [dbo].[tblObservations]
(
FormID
, Data
, UserID
, DateOfObservation
, Final
, ValidTo
, ID_Grading
, ID_ObservationKind
, Created
, Modified
, [RowVersion]
)
SELECT
t.FormID
, '0'
, t.UserID
, t.DateOfObservation
, t.Final
, t.ValidTo
, t.ID_Grading
, 40
, t.Created
, t.Modified
, t.[RowVersion]
FROM dbo.tblObservations t
LEFT JOIN dbo.tblObservations t2 ON
t.FormID = t2.FormID
AND t2.Data = '0'
AND t.UserID = t2.UserID
AND t.DateOfObservation = t2.DateOfObservation
AND t.Final = t2.Final
AND t.ValidTo = t2.ValidTo
AND t.ID_Grading = t2.ID_Grading
AND t2.ID_ObservationKind = 40
AND t.Created = t2.Created
AND t.Modified = t2.Modified
AND t.[RowVersion] = t2.[RowVersion]
WHERE t.ID_ObservationKind = 39
AND t.Data = 'No'
AND t.Final = 1
AND t2.FormID IS NULL
またはこれを試してください -
INSERT INTO [dbo].[tblObservations]
(
FormID
, Data
, UserID
, DateOfObservation
, Final
, ValidTo
, ID_Grading
, ID_ObservationKind
, Created
, Modified
, [RowVersion]
)
SELECT
t.FormID
, '0'
, t.UserID
, t.DateOfObservation
, t.Final
, t.ValidTo
, t.ID_Grading
, 40
, t.Created
, t.Modified
, t.[RowVersion]
FROM dbo.tblObservations t
WHERE t.ID_ObservationKind = 39
AND t.Data = 'No'
AND t.Final = 1
AND NOT EXISTS(
SELECT 1
FROM dbo.tblObservations t2
WHERE t2.ID_ObservationKind = 39
AND t2.Data = 'No'
AND t2.Final = 1
)