June 21, 2007 at 3:39 pm
Hello,
How can I use BCP to write the data to a text file but quote delimited format?
Thank you
June 21, 2007 at 11:43 pm
Exclusive help for BCP is available in BOL. did you check that. If you want us to script for you can be more specific.
Cheers,
Sugeshkumar Rajendran
SQL Server MVP
http://sugeshkr.blogspot.com
June 22, 2007 at 4:52 am
As long as the table is not huge, dts may be a better option for you as you want to amend the data on the way out.
---------------------------------------------------------------------
June 22, 2007 at 9:59 am
I would agree with George, you should look at DTS first. If BCP is required, you can use the queryout option with BCP. It would be a little bit of a pain, but it can be done.
BCP "SELECT '\"' + name + '\"' FROM sys.databases" QUERYOUT C:\Test.bcp -S localhost -T -c
I just tested this, and it works fine. You will have to put the delimeted quotes around each of the fields, but if BCP has to be used, this will work. Just remember to escape the double quote marks in your query.
One last thing, non text fields will have to be converted to text datatypes to allow concatenation (i.e. date, numeric). I really think DTS is the way to go, though.
June 22, 2007 at 10:44 am
Hi Guys,
Yuppp... DTS is the way to go... I was working on it for 3 hours and at the end, used DTS
Thank you
June 22, 2007 at 11:17 am
What about bcp out through a view ?
RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."
June 22, 2007 at 12:24 pm
didn't try that... but I guess it's gonna be the same result
no?
June 22, 2007 at 1:17 pm
If you use OSQL with the -h-1 option and the -o option, something like the following works very well...
USE Northwind
SET NOCOUNT ON
SELECT QUOTENAME('CustomerID','"')+','
+ QUOTENAME('CompanyName','"')+','
+ QUOTENAME('ContactName','"')+','
+ QUOTENAME('ContactTitle','"')+','
+ QUOTENAME('Address','"')+','
+ QUOTENAME('City','"')+','
+ QUOTENAME('Region','"')+','
+ QUOTENAME('PostalCode','"')+','
+ QUOTENAME('Country','"')+','
+ QUOTENAME('Phone','"')+','
+ QUOTENAME('Fax','"')
UNION ALL
SELECT QUOTENAME(ISNULL(CustomerID,''),'"')+','
+ QUOTENAME(ISNULL(CompanyName,''),'"')+','
+ QUOTENAME(ISNULL(ContactName,''),'"')+','
+ QUOTENAME(ISNULL(ContactTitle,''),'"')+','
+ QUOTENAME(ISNULL(Address,''),'"')+','
+ QUOTENAME(ISNULL(City,''),'"')+','
+ QUOTENAME(ISNULL(Region,''),'"')+','
+ QUOTENAME(ISNULL(PostalCode,''),'"')+','
+ QUOTENAME(ISNULL(Country,''),'"')+','
+ QUOTENAME(ISNULL(Phone,''),'"')+','
+ QUOTENAME(ISNULL(Fax,''),'"')
FROM dbo.Customers
--Jeff Moden
Change is inevitable... Change for the better is not.
June 22, 2007 at 2:13 pm
Jeff,
Thanks... your solution somehow works, but the only problem is that when I generate the file, I get this
1> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12> 13> 14>
and then there is like 6 CrLf
this is the way it looks:
1> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12> 13> 14> "f1","f2","f3","f4"
"1","1","0","11111111"
"12","1","0","11111111"
June 22, 2007 at 2:52 pm
What was the first post about?
I don't see any "quote delimited format" here.
Can you explain what exactly do you need?
_____________
Code for TallyGenerator
June 22, 2007 at 9:03 pm
Hello,
How can I use BCP to write the data to a text file but quote delimited format?
Thank you
June 22, 2007 at 9:04 pm
Sorry David, didn't list all of the switches you needed 'cause I thought you might already know them... You'll need the following switches, as well...
-s"" -w256 -n
Replace the "256" with the appropriate number and take a look at "OSQL" in Books Online to see what these switches do...
--Jeff Moden
Change is inevitable... Change for the better is not.
June 22, 2007 at 11:26 pm
Thanks a lot Jeff
I will try that
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply