i need to export 3 full sql table values in to a single excel sheet using store procedure.
i have done with single table ,
query i have used for single table :
set @sql='bcp "select * from Veest..ven_machinedescription_day_report " queryout c:\Daily_Reports\data_file.csv -c -t, -T -S' + @@servername
exec master..xp_cmdshell @sql
--Copy dummy file to passed EXCEL file
set @sql= 'exec master..xp_cmdshell ''type '+@data_file+' >> "'+@file_name+'"'''
exec(@sql)
--Delete dummy file
set @sql= 'exec master..xp_cmdshell ''del '+@data_file+''''
exec(@sql)
the above query is working fine..
for saving 3 tables values , i have done like this ,
set @sql='bcp "select * from Veest..ven_machinedescription_day_report " queryout c:\Daily_Reports\data_file.csv -c -t, -T -S' + @@servername
exec master..xp_cmdshell @sql
set @sql1='bcp "select * from Veest..ven_machinedescription_night_report " queryout c:\Daily_Reports\data_file.csv -c -t, -T -S' + @@servername
exec master..xp_cmdshell @sql1
set @sql22='bcp "select * from Veest..ven_machinedescription_midnight_report " queryout c:\Daily_Reports\data_file.csv -c -t, -T -S' + @@servername
exec master..xp_cmdshell @sql2
when i saw the data_file.csv, only the last execution (@sql2) is saved..the data is not being appended.. i need output similar to the below image..

some times the total columns numbers will be not same in all the 3 tables..
plz help me out to solve this issue..
thanks n regards,
T.Navin
Create a view. Then export from the view to Excel.