Below is the sample code to copy data from SQL server to Excel through BCP (Bulk Copy Program) uitlity.
declare @logtext varchar(100)
declare @cmd varchar(1000)
--set @logtext = 'Select top 10 * from Server.DB.Table'
SET @cmd = 'bcp "Select top 10 * from Server.DB.Table" queryout "c:\test\check.csv" -c -S Test/BK -T -t,'
EXEC master..XP_CMDSHELL @cmd
declare @logtext varchar(100)
declare @cmd varchar(1000)
--set @logtext = 'Select top 10 * from Server.DB.Table'
SET @cmd = 'bcp "Select top 10 * from Server.DB.Table" queryout "c:\test\check.csv" -c -S Test/BK -T -t,'
EXEC master..XP_CMDSHELL @cmd