how to bcp out from sybase few columns from a table with many columns? Also can some logic be accommodated while retrieving data?

bcp bulk sqlbulkcopy sybase-ase

Question

I have a huge table with 60 + columns in Sybase ASE, I want to bcp out 12 columns. I was checking syntax on manuals but could not find a way to mention column names.

I would also like to put some logic while retrieving data, like:

convt = case when A.isConvertible='0' then 'N' else 'Y'  end

Primarily I am looking for something like queryout available in SQL Server bcp.

I can not create objects on Sybase side. It's a source for me I can only do SELECT on it.

Popular Answer

This is fairly easy to do by creating a view with just the columns and values you want. You can then use bcp to retrieve data from the view.

Since you can't create objects in the database in question, that complicates things since bcp only supports exporting the full object.

One way around only having select permissions on the database in question, would be to create the view in tempdb. It won't be persistent between dataserver reboots, but it will allow you to bcp out the columns that you need.

A second work around might be to install an insance of ASE on your local system, and mount the remote tables via CIS (Component Integration Services). At that point, you should be able to create the view you need, and perform the bcp out from your local system.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why