sql server - csv output from windows batch + sqlcmd only returns first column -


i have looked on internet , cant seem find solution problem.

i trying output query results csv through using combination of sqlcmd , windows batch. here have far:

sqlcmd.exe -s %dbserver% -u %dbuser% -p %dbpass% -d %userprefix%  -q "select username, userdob, usergender table" -o %userdata%\%userprefix%\fact_bp.csv -h-1 -s"," 

is there i'm missing here? setting looks @ first column of query results?

any advice @ huge - i'm lost.

here reference page msdn on sqlcmd.

http://technet.microsoft.com/en-us/library/ms162773.aspx

i placed command in batch file in c:\temp go.bat.

sqlcmd -s(local) -e -dmaster    -q"select cast(name varchar(16)), str(database_id,1,0), create_date sys.databases"    -oc:\temp\sys.databases.csv -h-1 -s, 

notice hard coded file name , removed "" around field delimiter.

i expected output below.

enter image description here

either command not system variables or else wrong. please try code base line test. works sql 2012.

also, number of lines dumped file. must clear out of file. why not use sqlcmd etl.

why not use bcp instead?

i have writing several articles on website.

http://craftydba.com/?p=1584


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -