bcp

How to export SQL Server 2005 query to CSV

◇◆丶佛笑我妖孽 提交于 2019-11-27 17:47:37
I want to export some SQL Server 2005 data to CSV format (comma-separated with quotes). I can think of a lot of complicated ways to do it, but I want to do it the right way. I've looked at bcp, but I can't figure out how to put the quotes around the fields (except concatenating them to the field values, which is ugly). I guess I could do it with sqlcmd and -o, but that seems ugly for the same reason. Is there a bcp way to do it? Is there a reasonable sqlcmd way to do it? Is there some great, simple utility built into the Management Studio that I'm just overlooking? In Management Studio, select

How to make Microsoft BCP export empty string instead of a NUL char?

雨燕双飞 提交于 2019-11-27 17:42:22
问题 I was working trying to get this bcp tool to work in a particular way. The -c switch is supposed to export using chars, but for some reason there was a weird char showing in Notepad++ like if it was UNICODE or some other formatting. I wanted to get that char, which was an Empty string in the database, to export as an empty string into the text file. How do you do that? 回答1: Well, after looking around the web this is what I found. Thought to put it in SO so more people have access to it. http:

Bulk Load Files into SQL Azure?

僤鯓⒐⒋嵵緔 提交于 2019-11-27 17:36:02
问题 I have an ASP.NET app that takes multimegabyte file uploads, writes them to disk, and later MSSQL 2008 loads them with BCP. I would like to move the whole thing to Azure, but since there are no "files" for BCP, can anyone comment on how to get bulk data from an Azure app into SQL Azure? I did see http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy.aspx but am not sure if that applies. Thanks. 回答1: BCP is one way to do it. This post explains it in three easy steps: Bulk

Using bcp utility to export SQL queries to a text file

[亡魂溺海] 提交于 2019-11-27 15:07:47
问题 I debug a stored procedure (SQL Server 2005) and I need to find out some values in a datatable. The procedure is run by an event of the application and I watch just the debugging output. I do the following my stored procedure (SQL Server 2005), I took a system table (master.dbo.spt_values) as example: set @logtext = 'select name, type from master.dbo.spt_values where number=6' --set @logtext = 'master.dbo.spt_values' SET @cmd = 'bcp ' + @logtext + ' out "c:\spt_values.dat" -U uId -P uPass -c'

export table to file with column headers (column names) using the bcp utility and SQL Server 2008

久未见 提交于 2019-11-27 06:44:47
I have seen a number of hacks to try to get the bcp utility to export column names along with the data. If all I am doing is dumping a table to a text file what is the most straightforward method to have bcp add the column headers? Here's the bcp command I am currently using: bcp myschema.dbo.myTableout myTable.csv /SmyServer01 /c /t, -T The easiest is to use the queryout option and use union all to link a column list with the actual table content bcp "select 'col1', 'col2',... union all select * from myschema.dbo.myTableout" queryout myTable.csv /SmyServer01 /c /t, -T An example: create table

BCP returns no errors, but also doesn't copy any rows

情到浓时终转凉″ 提交于 2019-11-27 06:04:06
问题 I'm trying to dump a very large set of data from a .csv file into a SQL Server 2012 database. Rather than doing thousands of INSERTs, I'm investigating bcp . EDIT: This is for an automated process, and not just a one-off. I also do not have BULK INSERT rights to this database. When I try to copy data into the database, bcp doesn't return any errors, but also doesn't actually copy anything - it just returns 0 rows copied . I've whittled this down to a minimal case that doesn't work. First,

Use bcp to import csv file to sql 2005 or 2008

允我心安 提交于 2019-11-27 02:00:03
问题 I have a csv file and i need to import it to a table in sql 2005 or 2008. The column names and count in the csv are different from the table column names and count. The csv is splitted by a ';' . Example CSV FILEcontents: FirstName;LastName;Country;Age Roger;Mouthout;Belgium;55 SQL Person Table Columns: FName,LName,Country 回答1: I'd create a temporary table, bulk insert the lot, select into the new table what you need and drop the temporary table. Something like CREATE TABLE dbo.TempImport (

Exporting SQL Server Table to multiple part files

痴心易碎 提交于 2019-11-26 23:23:44
问题 I need to export a fairly large SQL Server table ~100GB to a CSV file. But rather than the output be a single csv file, it should ideally be multiple files say 10 files each 10GB. I see BCP has a batch_size argument but this still writes all data to a single file? Are there other free utilities for doing what I require? Either where the size of file can be specified in bytes or number of rows? For bit of context this is so the data can be combined with other sources in a Hive/Hadoop platform,

SQL Server BCP export corrupted file?

做~自己de王妃 提交于 2019-11-26 23:08:41
i have a small problem with BCP functionality in SQL Server 2012. The things is: im loading .jpg image (167KB in size) using below command: INSERT [tabela_testowa] ( Data ) SELECT * FROM OPENROWSET (BULK N'C:\foty\ch6_MagicShop.jpg', SINGLE_BLOB) a; and then im trying to export it back to disk using: BCP "SELECT data FROM tabela_testowa WHERE ID = 1" queryout "C:\test\file.jpg" -T -n -d test File gets saved on disk no problem, size is also 167 KB but.. it cant be opened like the original copy. I dont know whatever some parameter is wrong in BCP export? Or maybe it gets corrupted at import

How to export data from SQL Server 2005 to MySQL [closed]

a 夏天 提交于 2019-11-26 21:38:16
I've been banging my head against SQL Server 2005 trying to get a lot of data out. I've been given a database with nearly 300 tables in it and I need to turn this into a MySQL database. My first call was to use bcp but unfortunately it doesn't produce valid CSV - strings aren't encapsulated, so you can't deal with any row that has a string with a comma in it (or whatever you use as a delimiter) and I would still have to hand write all of the create table statements, as obviously CSV doesn't tell you anything about the data types. What would be better is if there was some tool that could