Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want to BCP certain searches into a text file 1

Status
Not open for further replies.

FatalExceptionError

Technical User
Apr 10, 2001
100
US
I need to BCP a table into a text file for use by others. This is normally simple but I can't BCP the whole table, just the results of a query based on a few things. I am sure it is something simple.

I need to know two things
1. Is it possible to BCP the results of a query and if it is how to do it?
2. The most efficient way to go about doing this as I am expecting the results to be quite large at times?

P.S. It is being run from a stored procedure but that should not change much.

The statement below is true
The statement above is false

There are 10 kinds of people, those who know binary and those who don't
 
When doing your BCP use QUERYOUT instead of OUT and put the query in instead of the table name.
Code:
BCP "select * from db1.dbo.table1 where c1 = 'test'" QUERYOUT ...

A better method if possible then running BCP from within a stored procedure (as it requires access to xp_cmdshell) is you have the stored procedure return a result set, then put the stored procedure in as the query to be returned.
Code:
BCP "exec db1.dbo.usp_something" QUERYOUT ..."

Denny
MCSA (2003) / MCDBA (SQL 2000)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Thank you for the information.

=======================================
The statement below is true
The statement above is false

There are 10 kinds of people, those who know binary and those who don't
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top