bcp

SQL BCP with column name

天涯浪子 提交于 2021-02-20 04:44:07
问题 I am trying to export my stored procedure to a .csv file using BCP. It does give me a output file in .CSV but it does not print column name. Below is the script. Please look at and let me know what i am missing DECLARE @command VARCHAR(4000) declare @fulldate varchar(30) = convert(varchar,GETDATE(),112) declare @year varchar(30) = left(@fulldate,4) declare @day varchar(30) = right(@fulldate,2) declare @month varchar(30) = left(right(@fulldate,4),2) DECLARE @FileDirectory VARCHAR(1000) = 'c:\'

BULK INSERT with two row terminators

≡放荡痞女 提交于 2021-02-07 19:43:41
问题 I am trying to import a text file, so the result would be just words in a seperate rows of one column. For example a text: 'Hello Mom, we meet again' should give 5 records: 'Hello' 'Mom,' 'we' 'meet' 'again' I tried to accomplish this with BULK INSERT with ROWTERMINATOR = ' ' , but there is a problem with treating new line as a terminator too and I get 'Mom,we' in one of the results. From what i know, there is no way to add a second ROWTEMRMINATOR to BULK INSERT (true?). What is the best way

How to remove NULL char (0x00) from object within PowerShell

心已入冬 提交于 2021-02-07 06:47:35
问题 I have a .CSV file that I created using SQL Server's BCP command-line BULK-COPY utility to dump a bunch of database tables. Since I want to import these .CSV file's using Powershell and convert them to a nice report using the format-table cmdlet, I'm having issues with columns lining up, etc,. because some columns contain NULLs from SQL Server. I don't have the option to convert the NULL from SQL Server first; due to the way I'm exporting the table to CSV. Therefore, I would like to remove

How to remove NULL char (0x00) from object within PowerShell

馋奶兔 提交于 2021-02-07 06:47:11
问题 I have a .CSV file that I created using SQL Server's BCP command-line BULK-COPY utility to dump a bunch of database tables. Since I want to import these .CSV file's using Powershell and convert them to a nice report using the format-table cmdlet, I'm having issues with columns lining up, etc,. because some columns contain NULLs from SQL Server. I don't have the option to convert the NULL from SQL Server first; due to the way I'm exporting the table to CSV. Therefore, I would like to remove

exec xp_cmdshell bcp syntax

血红的双手。 提交于 2021-02-05 06:56:25
问题 I can't seem to find the right syntax to export data with column names using exec xp_cmdshell bcp in sql server management studio.I've tried the below variations EXEC xp_cmdshell bcp "select "a_id","b_id","c_id" union select a_id,b_id,c_id from tablename out "\\network_path\a.txt" -c -Uusername -Ppassword -Sservername" And EXEC xp_cmdshell bcp 'select 'a_id','b_id','c_id' union select a_id,b_id,c_id from tablename out '\\network_path\a.txt' -c -Uusername -Ppassword -Sservername' And EXEC xp

Keep getting import error “String data, right truncation” using BCP

£可爱£侵袭症+ 提交于 2021-01-29 16:47:07
问题 I've hit a problem. I'm trying to use BCP to import about 700,000 records into a working table. This is the SQL I use to build my working table: If Exists (Select * From sys.tables Where [name] = 'InactiveIDs') Begin Drop Table [dbo].[InactiveIDs] End Create Table [dbo].[InactiveIDs] ( ContactId UniqueIdentifier Not Null, ID Varchar(50), EmailAddress VarChar(255) Not Null ) Create Index IX_ContactIdEmailAddress On [dbo].[InactiveIDs] (ContactId, EmailAddress) Here is the format file file: 13

BCP queryout from Azure VM : SQLState = 37000, NativeError = 40515 Reference to database and/or server name in 'DBName.dbo.TableName' is not supported

天涯浪子 提交于 2021-01-28 06:44:30
问题 I was trying to export a table from database in Azure VM into a text file using BCP in my Local Machine's SSMS. !! bcp "SELECT * FROM DBName.dbo.TableName" queryout D:\tablename.txt -S AzureVM -U userName -P passWord -n But following error was the result Starting copy... SQLState = 37000, NativeError = 40515 Error = [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Reference to database and/or server name in 'DBName.dbo.TableName' is not supported in this version of SQL Server. SQLState =

Opening .bcp files in R

风流意气都作罢 提交于 2021-01-28 05:53:53
问题 I have been trying to convert UK charity commission data which is in .bcp file format into .csv file format which could then be read into R. The data I am referring to is available here: http://data.charitycommission.gov.uk/. What I am trying to do is turn these .bcp files into useable dataframes that I can clean and run analyses on in R. There are suggestions on how to do this through python on this github page https://github.com/ncvo/charity-commission-extract but unfortunately I haven't

How to import a very large csv file into an existing SQL Server table?

谁说我不能喝 提交于 2020-08-27 05:56:07
问题 I have a very large csv file with ~500 columns, ~350k rows, which I am trying to import into an existing SQL Server table. I have tried BULK INSERT , I get - Query executed successfully, 0 rows affected . Interestingly, BULK INSERT worked, in a matter of seconds, for a similar operation but for a much smaller csv file, less than 50 cols., ~77k rows. I have also tried bcp , I get - Unexpected EOF encountered in BCP data-file. BCP copy in failed . The task is simple - it shouldn't be hard to