bcp

sql bcp utility -in with xlsx ( Excel ) file

霸气de小男生 提交于 2019-12-13 05:00:14
问题 How to use bcp utility to import data from xlsx to sql database. When i tried to import it throws error saying 'String data, right truncation'. Do i need to specify any format or delimiters option explicitly? If I try to export the data from database as xlsx file and import that back to DB it works fine. but the exported file is not properly formatted as i try to open it with office excel it show up in some weird format. 回答1: Don't use the xlsx file as it is, but save it in another format.

Problems with bcp output

百般思念 提交于 2019-12-13 02:50:25
问题 I have some problems with the following code. Main reason for this code is to export the SQL statement into a file. But it doesn't work and I don't see my mistake. DECLARE @DBName VARCHAR(5000); DECLARE @period VARCHAR(5000); DECLARE @SQLEXE VARCHAR(5000); DECLARE @SearchSchema VARCHAR(5000); SET @period = '''2017-01-01 00:00:00'' AND ''2017-12-31 23:59:59''' SET @DBName = (SELECT name FROM master.dbo.sysdatabases where name LIKE '%NAV%'); EXECUTE ('USE [' + @DBName+']'); SET @SearchSchema =

SQL 2012 bcp call returns SQLState = 28000. NativeError = 18456 Login failed for user

非 Y 不嫁゛ 提交于 2019-12-12 16:22:42
问题 I’m working with a SQL stored procedure that makes a call to xp_cmdshell. xp_cmdshell has been enabled, and has a proxy account set to ‘vpexporter’. This sproc was designed to write out a data file to disk. This sproc had been working when it was on a SQL 2005 server. The environment has been upgraded to SQL 2012 and the sproc no longer runs. The line making the call is: set @sql1 = 'bcp "SELECT * FROM dbo.udPayrollOutput" queryout "D:\Repository\Exports\' + @fileunique -Uvpexporter

BCP Import error “Invalid character value for cast specification”

左心房为你撑大大i 提交于 2019-12-12 12:37:36
问题 All I am using BCP for import export and getting "Invalid character value for cast specification" error for only 1(first row of export) row while trying to import back. Table Structure Col1 -- Numeric(19,0) Col2 -- NVARCHAR(400) Col3 -- NVARCHAR(400) I am using following commands FOR Export EXEC master..xp_cmdshell 'bcp "SELECT TOP 10 Col1, Col2, Col3 FROM Server.dbo.TableName" queryout C:\Data\File.dat -S Server -T -t"<EOFD>" -r"<EORD>" -w' Same way I am generating a FORMAT file EXEC master.

How do I grant access to SQL Server Agent to be able to write/modify system files?

筅森魡賤 提交于 2019-12-12 12:17:44
问题 I have a job that has a stored procedure that runs BCP to QUERYOUT some data. If I run the QUERYOUT command by itself, it works. However, if I try to run it in a JOB, it creates the file but "hangs" and the data is never put in the file. This hangs forever so I usually terminate the BCP.exe. My question is: How do I get a SQL job to run BCP to do a QUERYOUT and have the permissions to do so? The QUERYOUT is going to the C:\ drive (so nothing fancy or anything). This problem is driving me nuts

Best way to export/import MS Sql 2008 Geography data

我与影子孤独终老i 提交于 2019-12-12 09:37:51
问题 (ANSWER) How to export some Geography data from a Microsoft Sql Server 2008. You'll need to use the command line argument BCP to dump the data in it's original (native) format to a binary file. Then on the other server you can bulk insert this binary data back into a table of the same strucutre. here's some code. Export Command Line: bcp "geodata.dbo.GeographyData" out "C:\GeoData.bin" -T -n -S <servername> Notes This uses a Trusted connection use the bcp /? for more help for your export

BCP unexpected EOF

我只是一个虾纸丫 提交于 2019-12-12 06:45:15
问题 I try to do a bulk copy from a file into a table in sqlserver 2008. Its only a part of the file that I want to copy (in the BCP command example bellow it is only line number 3 I will copy). Sometimes I receive the "Unexpected EOF encountered" error message. The command is: BCP tblBulkCopyTest in d:\bc_file.txt -F3 -L3 -c -t, -S(local) -Utest -Ptest When the file looks like the following, the copy works fine (the line number 3 is inserted into my table): 44261233,207,0,0,2168 44261234,207,0,0

How to check table exist and then rename it

喜夏-厌秋 提交于 2019-12-12 05:14:19
问题 This question is similar to many other question but it have many other things to. I Have to create a query in which I have many thing: First check if table is already exist in the database or not which I know we can get from this IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'TheSchema' AND TABLE_NAME = 'x')) Second I need to update the table name if it is already an existing table EXEC sp_rename 'x','y' Third I have to check if it is not exist create it and then

SQL Server BCP Command not Writing NVARCHAR(MAX) Variable Contents to File

允我心安 提交于 2019-12-12 04:45:45
问题 I'm having issues with SQL Server's BCP . I'm not getting an error message but the command is also not writing anything to the path specified. Here is my code: In this scenario, the only variable not accounted for in the code below is @MESSAGE which is a NVARCHAR(MAX) and will take up most of that space so VARCHAR(8000) won't be nearly big enough. DECLARE @OUTPUT_TABLE VARCHAR(255) = '##temp' + CONVERT(VARCHAR(12), CONVERT(INT, RAND() * 1000000)) DECLARE @RESULT INTEGER DECLARE @OUTPUT

when to use a format file for bulk copy program (bcp)

时间秒杀一切 提交于 2019-12-12 04:28:56
问题 When would we use a format file for bcp? 回答1: Usually, when you have different column separators. For example: bob,"fred","tom"||harry rather than bob,fred,tom,harry The section "When Is a Format File Required?" describes it completely 来源: https://stackoverflow.com/questions/1994411/when-to-use-a-format-file-for-bulk-copy-program-bcp