Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server 2008 - General
»
BCP
BCP
Rate Topic
Display Mode
Topic Options
Author
Message
24tjf
24tjf
Posted Thursday, March 21, 2013 2:16 PM
Forum Newbie
Group: General Forum Members
Last Login: Monday, May 06, 2013 9:06 AM
Points: 9,
Visits: 45
I have a stored procedure that exports data from a table into .csv file. There are several different record sets that get exported. They are all comma delimited with double quotes as a text qualifier. All of my files export and you can double click open the .csv file into excel and everything is fine, except for one. The interesting thing about this record set is that some of the data has a trademark symbol.
BCP:
DECLARE @bcp varchar(1000) = 'bcp "SELECT * from dbo.tempExportData" queryout "' + @filePath + + @FileOutputName + '" -T -w';
EXEC @Result = xp_cmdshell @bcp;
In the process I am getting the data:
DECLARE @ColumnList varchar(5000)
select @ColumnList = coalesce(@ColumnList + ',','') + quotename(cast(Name as varchar(50)) , '"')
from tempdb.sys.columns
where object_id = object_id('tempdb..#tempData')
insert into dbo.tempExportData (outputData)
values (@ColumnList)
insert into dbo.tempExportData (outputData)
select
quotename(isnull(FieldA, ''), '"') + ',' +
quotename(isnull(FieldB, ''), '"')
from #tempData
CSV:
FieldA,"FieldB"
ACME®,"some more data"
,"even more data"
Big Company,"still more data"
All of the data is contained in column A of the spreadsheet and FieldA is not text qualified. If you open the .csv in notepad,textpad, etc all of the columns are text qualified. I know that I can open excel and use the import wizard to successfully import the data but I am wondering why when you open the .csv excel is not handling it correctly?
Let me know if you need more information.
Post #1434022
Evil Kraig F
Evil Kraig F
Posted Thursday, March 21, 2013 2:42 PM
SSCertifiable
Group: General Forum Members
Last Login: Today @ 3:05 PM
Points: 5,666,
Visits: 6,105
I have a bit of a confusion here. BCP can build a comma delimited file for you. Why are you pre-constructing the CSV? What other issue did it solve for you?
- Craig Farrell
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions
|
Forum Netiquette
For index/tuning help, follow these directions.
|
Tally Tables
Twitter: @AnyWayDBA
Post #1434032
24tjf
24tjf
Posted Monday, March 25, 2013 6:25 AM
Forum Newbie
Group: General Forum Members
Last Login: Monday, May 06, 2013 9:06 AM
Points: 9,
Visits: 45
I needed to text qualify the data as some of the data had commas in it, e.g. ACME, Inc.
Post #1434869
kevaburg
kevaburg
Posted Monday, March 25, 2013 7:32 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Today @ 12:19 PM
Points: 157,
Visits: 184
24tjf (3/25/2013)
I needed to text qualify the data as some of the data had commas in it, e.g. ACME, Inc.
http://msdn.microsoft.com/en-us/library/aa174646(v=sql.80).aspx
I think you will find BCP can perform that function in itself.
Post #1434904
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.