I have the following snippet where I output to an excel file. The problem is that not each field fits into its own cell. The whole output goes into one cell. Is there a way that you can output a query to an excel file and it basically shows up the way that it does when you run it from query analyzer in grid view.
DECLARE @cmd VARCHAR(2048)
SET @cmd = 'OSQL -SLOCALHOST -dPubs '
+ ' -Ume -Ppw'
+ ' -Q"set nocount on SELECT * FROM Authors"'
+ ' -oc:\authors.xls'
EXEC master..xp_cmdshell @cmd, NO_OUTPUT
DECLARE @cmd VARCHAR(2048)
SET @cmd = 'OSQL -SLOCALHOST -dPubs '
+ ' -Ume -Ppw'
+ ' -Q"set nocount on SELECT * FROM Authors"'
+ ' -oc:\authors.xls'
EXEC master..xp_cmdshell @cmd, NO_OUTPUT