Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 BCP Selective export

Author  Topic 

Dovinshka
Starting Member

6 Posts

Posted - 2006-01-10 : 22:07:43
Hi,

I need to be able to export from an existing database, all fields with a certain column id. I have been pointed in the direction of bcp, however I am having difficulty finding the right syntax.

Thanks,

D.

(P.S. MSSQL 2000 Server)

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-10 : 22:18:56
from SQLServer Books OnLine on bcp Utility
Syntax
bcp {[[database_name.][owner].]{table_name | view_name} | "query"}
{in | out | queryout | format} data_file
[-m max_errors] [-f format_file] [-e err_file]
[-F first_row] [-L last_row] [-b batch_size]
[-n] [-c] [-w] [-N] [-V (60 | 65 | 70)] [-6]
[-q] [-C code_page] [-t field_term] [-r row_term]
[-i input_file] [-o output_file] [-a packet_size]
[-S server_name[\instance_name]] [-U login_id] [-P password]
[-T] [-v] [-R] [-k] [-E] [-h "hint [,...n]"]

Example :
bcp "Northwind.Jane Doe.Jane's Orders" out "Jane's Orders.txt" -c -q -U"Jane Doe" -P"go dba"


-----------------
'KH'

Go to Top of Page

Dovinshka
Starting Member

6 Posts

Posted - 2006-01-10 : 22:45:16
Hi Khtan,

Yeah I did see that part of the syntax. I'm just a little lost specifying the column name. Tables have a 'fse_id' column to specify what belongs to whom.

I can see bcp "dbname.Jane Doe.Jane's Orders" out "Jane's Orders.txt" -c -q -U"user" -P"pass"
and out of all those command switches, I don't see what to use to specify where column = "fse_id"

Thanks,
D.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-10 : 22:56:56
if you need to specify which column to BCP out, use the queryout
bcp "select col1, col2, .. from dbname..tblname" QUERYOUT ....

-----------------
'KH'

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-12 : 00:23:50
Try

EXEC Master..xm_cmdShell 'bcp "Select columns from DBname..tableName" queryout "C:\result.txt" -c'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Dovinshka
Starting Member

6 Posts

Posted - 2006-01-12 : 21:35:07
Thanks for that guys. I will give it a shot.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-01-12 : 22:27:34
Why not just creat a view or use QUERYOUT

Has everyone given up?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page
   

- Advertisement -