October 23, 2018 at 8:41 am
Hi
I have below code . I want record should be inserted only in tblTest if No_ value in test exists in other table Test1.
insert into tblTest select [No_],[DocumentNo] from [test]
Thanks
October 23, 2018 at 9:01 am
If you know Test1.No_ column has unique values, then:
INSERT INTO [tblTest]
SELECT [test].[No_]
,[test].[DocumentNo]
FROM [test]
INNER JOIN [Test1]
ON [Test].[No_] = [Test1].[No_];
Else:INSERT INTO [tblTest]
SELECT [test].[No_]
,[test].[DocumentNo]
FROM [test]
WHERE EXISTS (
SELECT *
FROM [Test1]
WHERE [Test1].[No_] = [test].[No_]
);
Though, I would prefer to include the column list at the target,.
October 23, 2018 at 10:33 am
Hi GrassHopper
I have written below code . Is it ok
insert into tblTemp select A.[No_],A.[DocNo_] from [Test] as A
where exists (Select No_ from tblTemp as B where A.[No_] = B.No_)
Thanks
October 25, 2018 at 2:07 pm
That looks correct to me, yes.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply