Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


BCP


Author
Message
river1
river1
SSC Eights!
SSC Eights! (952 reputation)SSC Eights! (952 reputation)SSC Eights! (952 reputation)SSC Eights! (952 reputation)SSC Eights! (952 reputation)SSC Eights! (952 reputation)SSC Eights! (952 reputation)SSC Eights! (952 reputation)

Group: General Forum Members
Points: 952 Visits: 1356
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
SSC Veteran
SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)SSC Veteran (292 reputation)

Group: General Forum Members
Points: 292 Visits: 1347
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
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

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

By Rajesh
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14956 Visits: 38953
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
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 43
Thanks Lowell :-D,

this code is very used ....
Sigerson
Sigerson
Mr or Mrs. 500
Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)

Group: General Forum Members
Points: 551 Visits: 1232
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
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14956 Visits: 38953
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
Mr or Mrs. 500
Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)Mr or Mrs. 500 (551 reputation)

Group: General Forum Members
Points: 551 Visits: 1232
@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
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14956 Visits: 38953
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-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45066 Visits: 39904
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.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Wink

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