To be honest I do not really get the queries that you wrote.
Are you trying to build strings from your queries that you then pass again to your database?
You can just pass your values from one database to the other in one query:
/*
maybe you need to switch off identity on your target table
to get your original id values into the target table like this:
(without comment ofc ;))
*/
--SET IDENTITY_INSERT TargetDatabase.dbo.Countries ON
INSERT INTO TargetDatabase.dbo.Countries (Id, Name)
SELECT
CountryId, CountryName
FROM SourceDatabase.dbo.Country
--SET IDENTITY_INSERT TargetDatabase.dbo.Countries OFF
Or you can use a temporary table and switch the database connection after retrieving your original values.
USE SourceDatabase
DECLARE @TempTable TABLE (CountryId INT PRIMARY KEY, CountryName NVARCHAR(MAX))
INSERT INTO @TempTable (CountryId, CountryName)
SELECT
CountryId, CountryName
FROM Country
USE TargetDatabase
/*
maybe you need to switch off identity on your target table
to get your original id values into the target table like this:
(without comment ofc ;))
*/
--SET IDENTITY_INSERT Countries ON
INSERT INTO Countries (Id, Name)
SELECT
CountryId, CountryName
FROM @TempTable
--SET IDENTITY_INSERT Countries OFF
EDIT: as a previous poster mentioned, for this to work you need both databases on the same server, since you did not say anything about that i just assumed that that was the case? :D