I'm using the BCP utility to write SQL data to an output file. At random, some of the file contents are written in Mandarin (or so it seems), while the rest are written in English.
Here is the command I run from command prompt:
bcp.exe "SELECT * FROM MyTable" queryout "C:\Temp\MyTableExport.txt" -
e"C:\Temp\MyTableExport_Error.txt" -T -c -t, -S [server IP] -d [database]
Any idea why some of the files are outputting content in a different language?
Try this:
bcp.exe "SELECT * FROM MyTable" queryout "C:\Temp\MyTableExport.txt" -
e"C:\Temp\MyTableExport_Error.txt" -T -w -t, -S [server IP] -d [database]
Related
Need a Unix shell script to load the sqlServer table data into csv File.
Could some one please share the sample shell script.
Below Working:-->
sqlcmd -S $SQLHOSTNAME -U $SQLUSERNAME -P $SQLPASSWORD -d $SQLDATABASE -s" " -W -w 3000 -Q "SET NOCOUNT ON; $query;" | sed 2d >$csv_filename
I have an Azure SQL Server database and a linux box. I have a csv file on the linux machine that I want to import into SQL Server. I have a table already created where I am going to import this file.
Why does this command return an Unknown argument: -U?
bcp table in ~/test.csv -U myUsername -S databaseServerName -d dbName -q -c -t
When I rearrange the arguments passed to bcp like below, it returns an Unknown argument: -S
bcp table in ~/test.csv -S databaseServerName -d dbName -U myUsername -q -c -t
So contrary to the documentation:
https://learn.microsoft.com/en-us/sql/tools/bcp-utility?redirectedfrom=MSDN&view=sql-server-2017#U
I hit issues where bcp does not like spaces after the argument names.
https://granadacoder.wordpress.com/2009/12/22/bcp-export/
quote from the article above:
//
The other syntax sugar is that there is no space after the -S
argument. As seen below
-SMyServerName\MyInstanceName
bcp.exe "SELECT cast(LastName as char(50)) , cast(FirstName as
char(50)) , cast(MiddleName as char(50)) , cast(Suffix as char(50))
FROM MyAdventureWorksDB.Person.Person ORDER BY NEWID()" queryout
PeopleRock.txt -c -t -T -SMyServerName\MyInstanceName
also
https://www.easysoft.com/products/data_access/odbc-sql-server-driver/bulk-copy.html#importing-data-table
check your syntax sugar in linux (below example is from above easysoft link)
./bcp AdventureWorks.HumanResources.myTeam in ~/myTeam.csv \
-f ~/myTeam.Fmt -U mydomain\myuser -S mymachine\sqlexpress
Note the above has the dbname.schemaname.tablename (before the "in" word above)
Below is the code I am using in the batch script to BCP process.
call bcp.exe DBName.tablename out FILENAME.csv -e FILENAMEerr.txt -c -t"|" -U USER DETAILS -P PASSWORD -S Servicename -r"\n"
I try to run this on a SQL job:
sqlcmd -S . -d CI_Reports -E -s"," -W -Q "SET NOCOUNT ON SELECT * FROM [dbo].[Table]" > D:\Test.csv
How can I fix this error?
Sqlcmd: '> D:\Test.csv': Unexpected argument.
Have you tried like this -
sqlcmd -S . -d CI_Reports -E -s"," -W -Q "SET NOCOUNT ON SELECT * FROM [dbo].[Table]" -o D:\Test.csv
where -o output_file which would identify the file that receives output from sqlcmd.
Additionally you could try BCP which is best suited for bulk coping data between an instance of Microsoft SQL Server and a data file in a user-specified format.
Read more here.
exec master..xp_cmdshell'bcp "select * from [db name].[table name]"
queryout D:\testing1.xls -o "D:\querycommanddetails.txt" -T -c -C RAW'
I'm running above query on my local machine but System is showing output as 'NULL'.Can anybody help?
should be like this instead .. no queryout only out
exec master..xp_cmdshell'bcp "select * from [db name].[table name]"
out "D:\testing1.xls" -o "D:\querycommanddetails.txt" -e "D:\error.txt" -T -c -C RAW'
EDIT:
Try running this way from windows command prompt and see if it works
bcp "select * from [db name].[table name]" queryout "D:\testing1.xls" -c -T