• Hi deepti811,

    I will write an example again to show you what you need to do:

    --Step 1

    exec xp_cmdshell 'copy d:\templates\sales.xls d:\export\sales.xls'

    --Step 2

    insert into OPENROWSET(

    'Microsoft.Jet.OLEDB.4.0',

    'Excel 8.0;Database=d:\export\sales.xls;;HDR=YES',

    'SELECT * FROM [Sheet1$]')

    select * from sales_part1

    --Step 3

    insert into OPENROWSET(

    'Microsoft.Jet.OLEDB.4.0',

    'Excel 8.0;Database=d:\export\sales.xls;;HDR=YES',

    'SELECT * FROM [Sheet2$]')

    select * from sales_part2

    Step 1 copies the template excel file. The excel file has all the columns you want already in it (names only and columns formatted as needed).

    Step 2 inserts the first set of data into Sheet1

    Step 3 inserts the first set of data into Sheet2

    You can put this code into a loop or whatever you need, this is just an example to show how to write to multiple sheets. The directories and select statement can be changed however you need. The openrowset can also use UNC targets.

    It is quite simple really but if you don't understand what I mean please show me exactly where the problem is. Simply saying it doesn't work is an end-user error message 😀

    Regards,

    WilliamD