Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

BCP Expand / Collapse
Author
Message
Posted Thursday, March 21, 2013 2:16 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, October 15, 2013 11:12 AM
Points: 9, Visits: 47
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
Posted Thursday, March 21, 2013 2:42 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 11:07 AM
Points: 6,157, Visits: 7,218
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
Posted Monday, March 25, 2013 6:25 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, October 15, 2013 11:12 AM
Points: 9, Visits: 47
I needed to text qualify the data as some of the data had commas in it, e.g. ACME, Inc.
Post #1434869
Posted Monday, March 25, 2013 7:32 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, July 15, 2014 6:13 AM
Points: 307, Visits: 475
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 »

Add to briefcase

Permissions Expand / Collapse