I need to copy a part of table to file. But somehow neither "=" nor "in" work in the where clause
bcp "select Column1, Column2 from Table where Column1 in (100, 200, 300)" queryout "C:\file.txt" -S servername -U user -P password -c -t\t -r\r
It says "starting copy..." - and that's it.
Doing the same thing without where clause or with "<" or ">" works fine, but I need "in".
↧
bcp queryout: "in" and "=" do not work
↧
BCP Error: Error = [Microsoft][ODBC SQL Server Driver]Unable to resolve column level collations
When I try to BCP out the contents of Adventureworks in SQL Server 2005 with this command ...
bcp [AdventureWorks].[Sales].[Store] out "D:\MyDirectory\Sales_Store.bcp" -SPhilsTestServer\SQL2005 -n -T
I get the error
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver]Unable to resolve column level collations
but only with the STORE table. The rest works fine. Whereas the identical command
bcp [AdventureWorks].[Sales].[Store] out "D:\MyDirectory\Sales_Store.bcp" -SPhilsTestServer\SQL2008 -n -T
works fine with the SQL Server 2008 instance. I've googled for an answer to this and all I can find is a lot of other very frustrated people posting on forums the same question and getting a variety of answers, none of which helps any of them. Is this another of Microsoft's 'stealth' bugs or is there a simple answer?
↧
↧
how to import and export one column using bcp?
For example I have one table "dept" with two columns "id(primary), names(nvarchar(20))" in one server... And same table is in another server also...
I done export names column data to one "dept.txt" file... by using following command running in cmd
** bcp "select names from test.dbo.dept" queryout dept.txt -T -c -t "|" -r "\n"...
That is successfull....
But How to import the one column names data from dept.txt file to dept table.... ?
How to import only one column data into table by using bcp?
↧
bcp select where date between problem
The following works:
bcp tkcsdb.DBO.VP_TOTALS out c:\tkcsdb.dat -n -Usa -Pabc123de
and returns ~750k records. I'd like to limit the results by adding a date check against a field:
SELECT * FROM DBO.VP_TOTALS WHERE ADJUSTEDAPPLYDATE between '12/16/2011' and '12/31/2011';
which returns ~1200 records when fed to DTS. I've tried dozens of variations using bcp and gotten only mixed error codes as a result.
This is on Windows Server 2003 with MS SQL Server 80.
↧
how can save querry in text file,
xp_cmdshell'bcp "select top 5 * from sw_tokenDeletion"c:\TestMail\filename.txt" -c -U sa -P temp123 -S (172.25.11.20)'
Sir It is showing result
usage: bcp {dbtable | query} {in | out | queryout | format} datafile
[-m maxerrors] [-f formatfile] [-e errfile]
[-F firstrow] [-L lastrow] [-b batchsize]
[-n native type] [-c character type] [-w wide character type]
[-N keep non-text native] [-V file format version] [-q quoted identifier]
[-C code page specifier] [-t field terminator] [-r row terminator]
[-i inputfile] [-o outfile] [-a packetsize]
[-S server name] [-U username] [-P password]
[-T trusted connection] [-v version] [-R regional enable]
[-k keep null values] [-E keep identity values]
[-h "load hints"] [-x generate xml format file]
NULL
(12 row(s) affected)
Sir pls reply soon .........................(`_`)
↧
↧
BCP Utilityu with Remote server
0
Hi ,
My Query goes as shown below
Exec xp_cmdshell ' bcp "Select * from Test..T2" QueryOut "\\
[edit]
From the comments below:
> i am getting and Error Unable to Open BCP host data file whenever i am> trying to connect to remote server i.e Queryout "\RemoteseverC$..
↧
How to use BCP to dump query (cdc function ) retrieved data to text file
Im trying to use BCP to dump data from CDC function into a .dat file.
Im using the following query (which works in Server 2008 R2):
USE LEESWIJZER
DECLARE @begin_time datetime
, @end_time datetime
, @from_lsn binary(10)
, @to_lsn binary(10)
SET @end_time = '2013-07-05 12:00:00.000';
SELECT @to_lsn = sys.fn_cdc_map_time_to_lsn('largest less than or equal', @end_time);
SELECT @from_lsn = sys.fn_cdc_get_min_lsn('dbo_LWR_CONTRIBUTIES')
SELECT sys.fn_cdc_map_lsn_to_time(__$start_lsn) AS ChangeDTS
, *
FROM cdc.fn_cdc_get_net_changes_dbo_LWR_CONTRIBUTIES (@from_lsn, @to_LSN, 'all')
(edited for readability, used in BCP as single string)
my BCP string is:
BCP "Query above" queryout"C:\\temp\\LWRCONTRIBUTIES.dat" -w -t ";|" -r \\n -T -S {server\\\\instance} -o "C:\\temp\\LWRCONTRIBUTIES.log"
As you can see I want a resulting .dat file in unicode, and a log file.
I'm guessing the "ChangeDTS" column added to the function outcome is causing my problem.
Error message reads: "[Microsoft][SQL Native Client]Host-file columns may be skipped only when copying into the Server".
It may be resolved using a format file, but since this code needs to run daily, likely more than once daily, and the tables are subject to change, im reluctant to constantly adjust my format files (there are 100's of tables needing the same procedure).
Furthermore, this is run on a clients database, who probably wont like me creating views in their database.
.
Anybody got any idea how I can create a text file with a selected number of columns from a cdc function?
cheers
Wouter
↧
bcp out gives login failed
I have enabled 'xp_cmdshell', not sure why? created sample table in adventureworks2008 called Exporttab, I started cmd prompt by clicking start cmd and typed the bcp syntax to export out the table but gives me login error. have attached screen shot. what am i doing wrong?
↧
i need help with bcp connection to my sql server
PLEASE COULD SOMEONE HELP ME; BCP COULD NOT CONNECT TO SQL SERVER BUT MY SQL SERVER IS ON AND WINDOWS AUTHENCATION IS ALLOWED BUT I COULD NOT USE BCP TO TRANSFER A TEXT TO POPULATE A TABLE IN MY MOVIE DATABASE. PLEASE COULD ANYONE HELP;
Error = [Microsoft][SQL Server Native Client 10.0]Named Pipes Provider: Could no
t open a connection to SQL Server [2].
SQLState = 08001, NativeError = 2
Error = [Microsoft][SQL Server Native Client 10.0]A network-related or instance-
specific error has occurred while establishing a connection to SQL Server. Serve
↧
↧
Help with XML format file, import int and fixed binary
I have a text file where each record of three fields looks like this:
**0000###** [tab] **000####** [tab] **fixed-length binary 2037 bytes** [crlf]
(The numbers in the first two fields are 6-characters, padded with leading zeros)
I'm trying to import them into a table in 2008 R2 that looks like this:
**int int binary(2037)**
I've had no success with putting an XML format file together to do this. Here's may latest attempts at SQL CODE and FORMAT FILE:
INSERT INTO BinTest (ID, Buffer, Bin2037)
SELECT ID, Buffer, Bin2037
FROM OPENROWSET(BULK 'D:\Temp\Bin.txt',
FORMATFILE='D:\Temp\Bin.Xml'
) AS t1;
GO
These are the errors I get with this attempt:
*Msg 4864, Level 16, State 1, Line 9
Bulk load data conversion error (type mismatch or invalid character for the specified codepage) for row 1, column 3 (Buffer).
Msg 4832, Level 16, State 1, Line 9
Bulk load: An unexpected end of file was encountered in the data file.
Msg 7399, Level 16, State 1, Line 9
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 9
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".*
Please help!
↧
i run this script but there is some errors can anybody help me?
declare @cmd nvarchar(255);
-- Please note that the fully qualified table name is needed
select @cmd = '
bcp "select CAST(ID AS VARCHAR(1)),NAme from model.dbo.BB row for xml auto, root(''rows''), elements" ' +
'queryout "E:\sample.xml" -S IBIMAR\SQL2008 -T -w -r -t';
exec sys.xp_cmdshell @cmd;
> ---------------
Err:
NULL
Starting copy...
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Code page 720 is not supported by SQL Server
SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver]Unable to resolve column level collations
NULL
BCP copy out failed
NULL
↧
.xls file created using bcp command cannot be opened in c#
I want a stored procedure to take backup of sq l tables and i want to retrieve and view in website.so i decided to export sql table to excel sheet(.xls) file,but when i retrieved it using Microsoft.jet.oledB driver....it throws error as EXTERNAL TABLE IS NOT IN THE SPECIFIED FORMAT......
1.when i try to open .xls file simply,it shows the file you are trying to open,'filname.xls' is in a different format,than specified by the file extension.Verify that the file is not corrupted and is from a trusted source before opening the file......
If i create a normal .xls file manually,i could open it in c# using microsoft.jet.oledb driver.....
So please give me any solution...
↧
Stored procedure for data importing from flat files. Need some tips.
I am currently working on creation of SP to automate the process of importing flat data into SQL Server.
I want you to give me some useful advice on the best way how to realise, taking into account things I need:
1. File path and name, delimeter sign, table name as variables.
2. Logging process of importing in one file for every import task (errors and output results like in bcp)
3. Process flat files with different column order
4. Check if data we are trying to import already exists in database (don't replicate)
5. Batch import
6. Error cathing
Okay, now my thoughts. I would use either bcp or BULK INSERT.
Declare delimeter, source file, table as variables.
To identify column order I think we should parse first row with names and use intermediate table from which we then INSERT...SELECT into destination table in the right order.
Check if data already EXISTS before importing.
Still don't know about logging in one file with timeline. Any other errors that may occur?
Any advice would be appreciated. Thank you in advance.
↧
↧
Handling XML output to a file
Hello,
Several years ago, I build a system for a customer which produced XML output from a query. The calling VB .NET program calls BCP to run the stored procedure, and outputs the data to an XML file. This worked really well for many years, but the customer had a problem. The problem was that the file output is essentially a long single line of data. The pseudo code of the stored procedure looks like this:
- Make temporary tables
- Do a couple of SELECTS to fill temp
tables
- Do a SELECT ... FOR XML PATH...
In a recent upgrade, the customer requested that I changed the output so there are line feeds at the end of certain tags. This makes reading the data easier, and it has some other benefits to the customer. I couldn't find anything in the BCP options to handle this, so I made the following change to the query:
- Make temporary tables
- Do a couple of SELECTS to fill temp
tables
- Do a SELECT INTO XML type
- SET a STRING variable = XML type
- Go through STRING variable an insert
at the end of certain tags.
This works fine for queries returning under 30K records of about 1500 characters each. However, SQL Server crashed when attempting to handle a query of 60K records. The major difference in queries is transferring the XML data into the STRING variable. When looking up the limits of the STRING, I found that the upper limit is 2^31 characters, which seemed like more than enough space.
Has anyone had to output large XML files with line feeds? Is there a better method than using BCP? Or would I be better off importing the output into my program, and using the .NET XML tools to output this data to a file?
Any thoughts or advice would be welcome.
Best Regards,
halciber
↧
invalid buffer size for BCP column property
Created a format file:bcp DBNAME.test format NUL -c -t "" -T -f test.fmt
(fixed-width file)
Table and file Definition:
Length
5
21
10
1
8
15
10
10
3
8
20
30
30
20
2
30
4
23
10
40
100
1
Format File Definition (attached)
BCP Code: bcp DB_NAME.test in test.txt -T -f test.fmt
I checked the file for hidden characters, spaces, etc.
[1]: /storage/temp/1548-test.txt
↧
bcp queryout: "in" and "=" do not work
I need to copy a part of table to file. But somehow neither "=" nor "in" work in the where clause
bcp "select Column1, Column2 from Table where Column1 in (100, 200, 300)" queryout "C:\file.txt" -S servername -U user -P password -c -t\t -r\r
It says "starting copy..." - and that's it.
Doing the same thing without where clause or with "<" or ">" works fine, but I need "in".
↧
Getting error in BCP
While running the BCP command in SQL server Management Studio am getting the error :
CTLIB Message: - L5/O3/S5/N4/5/0:
ct_connect(): network packet layer: internal net library error: Net-Lib protocol driver call to connect two endpoints failed
Establishing connection failed.
NULL
How can i resolve the issue. Thanks in advance .
↧
↧
LOADING file with special charectors and japaneese charectors
HI Group,
I am trying to load a file japaneese and special charectors .
problem is that
japaneese will load when i convert my utf-8 file to utf-16 and bcp it (special charectors are not loading inthis scenerio)
special charectors are loading if i convert utf-8 to ANCI and then bcp in (japaneese are not loading in this case )
i want to load both the charectors .
its urgent ...any help buch of thanks.....
↧
Bcp error unable to open host file on network drive
I am working on a virtual machine with sql server 2008(R2). I am trying to use bcp command to export table data on network drive but its giving bacp cannot open host file error.
the command is
EXEC xp_cmdshell 'bcp "SELECT * FROM ayn.dbo.temp_tableforbcp " queryout "\\clt.alexandercc.local\Userdata\HomeFolders\volpj01\data.xls" -c -S ALEXSQLP -U sa -P AYN1965 '
I think I have all necessary permission for sql server to access network drive but it is still giving me the error.pls tell me what permissions do I need to check
↧
How do I load a bcp file into SQL Server?
I read the article "The subscription list problem":
https://ask.sqlservercentral.com/questions/1227/the-subscription-list-sql-problem.html
and I downloaded the registration file:
http://www.simple-talk.com/blogbits/philf/registrations.zip
I don't know how to load the *.bcp file into SQL server?
Can someone help me please?
Thanks,
Oded Dror
↧