You are missing spaces in your concatenated string and you also need to quote your filename. I also don't see the point of mixing concatenation and calling sp_executesql with parameters.
Try changing this part:
set @insertvariable = N'
BULK INSERT dbname.dbo.tablename' + @p1 + 'FROM' + @var5 + 'WITH
(
FIRSTROW = 1,
ORDER (Id),
CODEPAGE = Finnish_Swedish_CI_AS,
FIELDTERMINATOR = \t,
ROWTERMINATOR = 0x0a,
TABLOCK,
ERRORFILE = @var3,
FORMATFILE = @formatFile,
KEEPNULLS
);'
exec sp_executesql @insertvariable, N'@p1 nvarchar, @var5 nvarchar, @var3 nvarchar, @formatFile nvarchar', @p1, @var5, @var3, @formatFile
end
Into this, mind the spaces where you concatenate @p1 and @var5 and single quotes:
set @insertvariable = N'
BULK INSERT dbname.dbo.tablename ' + @p1 + ' FROM ''' + @var5 + ''' WITH
(
FIRSTROW = 1,
ORDER (Id),
CODEPAGE = Finnish_Swedish_CI_AS''Finnish_Swedish_CI_AS'',
FIELDTERMINATOR = \t,
ROWTERMINATOR = 0x0a,
TABLOCK,
ERRORFILE = ''' + @var3 + ''',
FORMATFILE = ''' + @formatFile + ''',
KEEPNULLS
);'
exec sp_executesql @insertvariable
end