Here is the skeleton of how, I'll let you flesh it out...
CREATE TABLE #FileListTable -- List of sql Files to run
(
RowID int IDENTITY
, FileName varchar(100)
, PassCount int DEFAULT 0
)
DECLARE
@FileToRun varchar(100),
@SQLCmd varchar(1000),
@bcpCmd varchar(1000),
@CurrentRow int,
@TotalRows int
SELECT
@FileToRun = '',
@SQLCmd = 'dir c:\Sale\*.* /b ',
@CurrentRow = 1
-- Use BULK INSERT to load the FileList
INSERT INTO #FileListTable
EXECUTE master.dbo.xp_cmdshell @SQLCmd
DELETE
FROM #FileListTable
WHERE ( FolderName IS NULL
OR FolderName = 'Output'
)
SELECT @TotalRows = count(1)
FROM #FileListTable
WHILE ( @CurrentRow <= @TotalRows )
BEGIN
SELECT @FileToRun = FileName
FROM #FileListTable
WHERE RowID = @CurrentRow
SELECT @BCPCmd = 'BULK INSERT PosMaster FROM c:\Sale\' + @FileToRun +
'WITH ( FirstRow = 1, FieldTerminator = '','', + RowTerminator = ''\n'')'
EXECUTE master.dbo.xp_cmdshell @BCPCmd
SET @CurrentRow = ( @CurrentRow + 1 )
END
The error indicates that your table, PosMaster, does not have the same number of columns as the data file, or the datatypes do not 'match' for one or more columns.
Carefully check your datafile.