SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


BCP


Author
Message
river1
river1
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11334 Visits: 1737
Hi,

i need to export data from a view to a PSV file.
I'm traing to do this t-sql:

exec master..xp_cmdshell 'bcp "select * from [database]..test1" queryout "c:\Import.psv" -T -S "server\instancename"'

I receive an error:

Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot resolve collation conflict for replace operation.


I want to export this data to a unicode PSV so that people from Oracle can import it.
Can someone help please?


thank you
Saravanan_tvr
Saravanan_tvr
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2056 Visits: 1355
Use this format...

declare @sql varchar(8000)
declare @path varchar(8000)
set @path ='d:\import.psv'
select @sql = 'bcp "set fmtonly off select * from db_name.DBO.table_name" queryout '+@path+' -c -t^ -T -S' + @@servername
exec master..xp_cmdshell @sql

this will give u the Psv format with tab delimiter..

Many Thanks!
S.saravanan
“I am a slow walker, but I never walk backwards-
Abraham Lincoln”
er.rajesh89
er.rajesh89
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 Visits: 44
hi if u can send code for import using " bcp in "

By Rajesh
Lowell
Lowell
SSC Guru
SSC Guru (182K reputation)SSC Guru (182K reputation)SSC Guru (182K reputation)SSC Guru (182K reputation)SSC Guru (182K reputation)SSC Guru (182K reputation)SSC Guru (182K reputation)SSC Guru (182K reputation)

Group: General Forum Members
Points: 182257 Visits: 41569
er.rajesh89 (5/2/2012)
hi if u can send code for import using " bcp in "

By Rajesh


Booksonline and google are great resources, but if you need an example, here's both an out and in in:

--using a super special 4 char row delimiter to be sure it doesn't exist in the data
--flags explanation:
-- -c = charcater data
-- -t"[||]" = field terminator
-- -r"[~~]" = row terminator
-- -T' = Trusted connection
--out
EXECUTE master.dbo.xp_cmdshell 'bcp "SELECT EMAILTEMPLATESID, EMAILBODY FROM Sandbox.dbo.EMAILTEMPLATES ORDER BY EMAILTEMPLATESID" queryout c:\Data\bcpExample.txt -c -t"[||]" -r"[~~]" -T'
--in
EXECUTE master.dbo.xp_cmdshell 'bcp Sandbox.dbo.EMAILTEMPLATES in c:\Data\bcpExample.txt -c -t"[||]" -r"[~~]" -T'
--in via bulk insert
BULK INSERT EMAILTEMPLATES FROM 'c:\Data\bcpExample.txt'
WITH (
DATAFILETYPE = 'char',
FIELDTERMINATOR = '[||]',
ROWTERMINATOR = '[~~]',
FIRSTROW = 1
)



Lowell
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
er.rajesh89
er.rajesh89
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
Points: 42 Visits: 44
Thanks Lowell :-D,

this code is very used ....
Sigerson
Sigerson
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1941 Visits: 1242
This is a related question, hoping someone on this thread can answer it.

I've had a working bcp process for months that creates a CSV file on a network drive. Here's the command:


'bcp "exec [dbname].[dbo].ExtractData" queryout ' + @destFolder + @fileName + ' -t \, -T -c'

When @destFolder = "\\[server_name]\UploadFiles" it works

If I change @destFolder to: "\\[server_name]\9 Auto Generated Upload Files\" with spaces in the folder name, it doesn't work.

I can work around this, but does anyone know of a way to force bcp to accept spaces in the destination folder?

Thanks in advance,

Sigerson

"No pressure, no diamonds." - Thomas Carlyle
Lowell
Lowell
SSC Guru
SSC Guru (182K reputation)SSC Guru (182K reputation)SSC Guru (182K reputation)SSC Guru (182K reputation)SSC Guru (182K reputation)SSC Guru (182K reputation)SSC Guru (182K reputation)SSC Guru (182K reputation)

Group: General Forum Members
Points: 182257 Visits: 41569
Sigerson (3/1/2013)
This is a related question, hoping someone on this thread can answer it.

I've had a working bcp process for months that creates a CSV file on a network drive. Here's the command:


'bcp "exec [dbname].[dbo].ExtractData" queryout ' + @destFolder + @fileName + ' -t \, -T -c'

When @destFolder = "\\[server_name]\UploadFiles" it works

If I change @destFolder to: "\\[server_name]\9 Auto Generated Upload Files\" with spaces in the folder name, it doesn't work.

I can work around this, but does anyone know of a way to force bcp to accept spaces in the destination folder?

Thanks in advance,


it's the usual command line thing: files or paths that contain spaces must be wrapped with double quotes

your code modified:note the dbl quotes that make up the path+file, and also for the t delimiter

'bcp "exec [dbname].[dbo].ExtractData" queryout "' + @destFolder + @fileName + '" -t "\", -T -c'



Lowell
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Sigerson
Sigerson
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1941 Visits: 1242
@Lowell,

Thanks for the quick answer. Yes, a rookie mistake. (pause for hanging head in shame)

Is there a word for having to learn so many fine points that one begins to forget the basics? Ermm

Thanks again,

Sigerson

"No pressure, no diamonds." - Thomas Carlyle
Lowell
Lowell
SSC Guru
SSC Guru (182K reputation)SSC Guru (182K reputation)SSC Guru (182K reputation)SSC Guru (182K reputation)SSC Guru (182K reputation)SSC Guru (182K reputation)SSC Guru (182K reputation)SSC Guru (182K reputation)

Group: General Forum Members
Points: 182257 Visits: 41569
Sigerson (3/1/2013)
@Lowell,

Is there a word for having to learn so many fine points that one begins to forget the basics? Ermm


Oh yea,the only guys that remember it all, i think I hear it described as "no personal life" the most :-D



Lowell
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (505K reputation)SSC Guru (505K reputation)SSC Guru (505K reputation)SSC Guru (505K reputation)SSC Guru (505K reputation)SSC Guru (505K reputation)SSC Guru (505K reputation)SSC Guru (505K reputation)

Group: General Forum Members
Points: 505429 Visits: 44253
Lowell (3/1/2013)
Sigerson (3/1/2013)
@Lowell,

Is there a word for having to learn so many fine points that one begins to forget the basics? Ermm


Oh yea,the only guys that remember it all, i think I hear it described as "no personal life" the most :-D



Heh... we can coin a new phrase, Lowell. "NPL" for "No Personal Life". I won't hazard the pronunciation of the acronym, though. :-P

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search