1

I have this info from a text file (via Notepad):

FName           LName           age     Location
....................................................
Dave            Thomas          24      New York
John            Stockton        24      Las Vegas
Jerry           Sloan           25      Los Angeles

I got these results after running a command file where it does an automation and creates this file with the results above. I want to be able to take that information and export it to Excel. How can I do this?

I tried to use something like this in the command prompt but the EXEC command doesn't exist:

EXEC master.dbo.xp_cmdshell 'bcp [database_name.Results] out "C:\Test.xls" -c -t\t -T -SServerName'
user2302629
  • 21
  • 2
  • 4
  • bcp is a program (bcp.exe). the code you posted is if you run it from within SQL. To run it from a command prompt the command would be `bcp [database_name.Results] out "C:\Test.xls" -c -t\t -T -SServerName` – MillhouseD Feb 03 '17 at 16:27
  • Its asking for a password. – user2302629 Feb 03 '17 at 16:42
  • The -T argument specifies a trusted connection. It will your your current context and should not ask for a password if your account has permissions to the object you are exporting. `bcp.exe master.sys.databases out D:\temp\dblist.txt -c -t\t -S yourservernamehere -T` – MillhouseD Feb 03 '17 at 16:50

1 Answers1

0

Here's a to the source on GitHub for a command-line tool I wrote to export a query result to a new Excel document file (with xslx extension - not a tab-delimited text file pretending to be an Ecel document).

bcp2excel command-line tool

Hope you find it useful :-)

Mitselplik
  • 1,079
  • 1
  • 12
  • 16