Link to home
Start Free TrialLog in
Avatar of toooki
toooki

asked on

SQL server 2005 command line client

Is there any client program available to connect to SQL server 2005 or SQL server 2008 via the server name and login credentials and then run sql query to dump the output to a .csv file?

I do the same way with mysql server. I have mysql client and I connect to the database and query via an automated script. Can I do the same for SQL server 2005 database?
ASKER CERTIFIED SOLUTION
Avatar of JoeNuvo
JoeNuvo
Flag of Viet Nam image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of toooki
toooki

ASKER

Thank you.
It seems I need Python installed in order to use sqlcmd .
Avatar of Ryan McCauley
You don't need Python to use SQLCMD - it's installed as part of the SQL Server Client Connectivity option, and you can use it without any additional installs. The first link JoeNuvo provides is exactly what you're looking for, if I understand your question correctly.
Avatar of toooki

ASKER

Yes that is right. Thank you.
I just worked on my laptop that has SQL Server 2005 express installed.
Is there any way to make it work on a Linux server that does not have SQL Server 2005 installed?
Are you talking about a Linux version of SQLCMD that connects to SQL Server databases, or one that connects to MySQL databases? I don't believe a SQL Server version of this tool exists for Linux, but I'd be surprised if a version for MySQL wasn't installed as part of the client tools.
Avatar of toooki

ASKER

Thanks.Yes you are right..
I was asking about a Linux version of SQLCMD that connects to Microsoft SQL Server database. I understand that may not exist. So I cannot run SQLCMD on a Linux server.

Yes I used MySQL on Linux server and that works..

But was wondering if I could connect to another Microsoft SQL Server from this Linux server...looks like I cannot.
since I don't have linux myself, I can't try the sqlcmd from URL I given to you.
if you think it worth your time, you should give it a try.
Avatar of toooki

ASKER

Yes, I looked at the documentation for the Linux sqlcmd tool. But the README file says:
sqlcmd requires the following:

Python 2.5 or better
The Grizzled API (automatically installed if you use easy_install to install sqlcmd)
The enum package (automatically installed if you use easy_install)
Appropriate Python DB API drivers for the database(s) you want to use. (See Database Types, below.)
Windows only: You'll also want the ipython pyreadline package, available via easy_install or from http://ipython.scipy.org/dist 


I do not have permission to install Python or so on the Linux server.

Avatar of toooki

ASKER

I am trying to run the sqlcmd on a Windows server. And the sqlcmd is downloading the dump file. The problem is that the file gets padded by huge amount of blank spaces.

My sqlcmd is:
sqlcmd -U myUser -P myPwd -S myServer.myco.com -d myDB -Q "select LTRIM(RTRIM(F1)), LTRIM(RTRIM(F2)) from dbo.myTab" -o "D:\myFile.txt" -s","

Problem is not at the source table. I do not know how to get rid of these blank spaces. The sqlldr command cannot detect the file content.

 dump.txt
to run on Windows with sql installed, maybe using BCP is better way.

try following command

BCP "select LTRIM(RTRIM(F1)), LTRIM(RTRIM(F2)) from myDB.dbo.myTab" queryout D:\myFile.txt -c -t\t -r\n -U username -P password -S myServer.myco.com

note
1) output will have tab as delimit
2) I don't sure about BCP tool for linux, but from what I looking for, it also required Python which is not able to do in your situation.
Avatar of toooki

ASKER

JoeNuvo, thank you for the help but the BCP command did not work. Got syntax error/etc. So I am ok with the sqlcmd and I will trim the values before loading to sqlldr. Seems it is working.
Thanks everyone for help.