You should write as:
-- STEP2: Insert records:
INSERT INTO @Travels
SELECT CountryId,VisitorId,0 FROM -- 0 = false for IsVisited
(
-- STEP1: first create a combination for all visitor Id and country Id
-- and get all the combinations which are not there in existing Travels table
SELECT C.CountryId,V.VisitorId
FROM @Country C
CROSS JOIN @Visitor V
EXCEPT
SELECT CountryId,VisitorId
FROM @Travels
) AS T
else if you want to create an entry for each combination in Country
and Visitor
write as:
-- STEP2: Insert records:
INSERT INTO @Travels
SELECT CountryId,VisitorId,0 FROM
(
-- STEP1: first create a combination for all visitor Id and country Id
SELECT C.CountryId,V.VisitorId
FROM @Country C
CROSS JOIN @Visitor V
) AS T
SELECT * FROM @Travels
0
solved Sql Select From multiple table [closed]