August 11, 2009 at 8:40 am
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
February 15, 2010 at 12:46 am
May 2, 2012 at 9:41 am
hi if u can send code for import using " bcp in "
By Rajesh
May 2, 2012 at 9:46 am
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
May 3, 2012 at 5:24 am
Thanks Lowell :-D,
this code is very used ....
March 1, 2013 at 8:14 am
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
March 1, 2013 at 8:30 am
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
March 1, 2013 at 9:05 am
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
Lowell
March 2, 2013 at 7:04 am
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
Heh... we can coin a new phrase, Lowell. "NPL" for "No Personal Life". I won't hazard the pronunciation of the acronym, though.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy