dbTalk Databases Forums  

Exporting out of SQL server -- comma in my column data

microsoft.public.sqlserver.misc microsoft.public.sqlserver.misc


Discuss Exporting out of SQL server -- comma in my column data in the microsoft.public.sqlserver.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Milagro
 
Posts: n/a

Default Exporting out of SQL server -- comma in my column data - 08-23-2007 , 10:11 PM






Hi,

I've taken over an SQL server 2005 express database. The database has
about 100,000 records in it. My client has asked me to pull out a
subset of data and save it into a .csv file, so they can later import
it into Excel.
I wrote and ran my query, and it worked very well. I exported the
result set (Save as ...) into a file.
However, when trying to import it into Excel I see a big problem. One
of the columns has data in it that contains commas. So, of course Excel
isn't importing the data correctly because it's splitting on the comma
for new rows when it's actually not a row.
Short of modifying all my data in the database(which can't be the best
solution), is there a simple way either in Sql Server or Excel where I
can export/import this data correctly?

Thanks,

M




Reply With Quote
  #2  
Old   
Ed Murphy
 
Posts: n/a

Default Re: Exporting out of SQL server -- comma in my column data - 08-23-2007 , 10:25 PM






Milagro wrote:

Quote:
I've taken over an SQL server 2005 express database. The database has
about 100,000 records in it. My client has asked me to pull out a subset
of data and save it into a .csv file, so they can later import it into
Excel.
I wrote and ran my query, and it worked very well. I exported the result
set (Save as ...) into a file.
However, when trying to import it into Excel I see a big problem. One of
the columns has data in it that contains commas. So, of course Excel
isn't importing the data correctly because it's splitting on the comma
for new rows when it's actually not a row.
Short of modifying all my data in the database(which can't be the best
solution), is there a simple way either in Sql Server or Excel where I
can export/import this data correctly?
CSV is evil. Try tab-delimited.


Reply With Quote
  #3  
Old   
Milagro
 
Posts: n/a

Default Re: Exporting out of SQL server -- comma in my column data - 08-24-2007 , 01:56 PM



On 2007-08-23 23:25:43 -0400, Ed Murphy <emurphy42 (AT) socal (DOT) rr.com> said:

Quote:
Milagro wrote:

I've taken over an SQL server 2005 express database. The database has
about 100,000 records in it. My client has asked me to pull out a
subset of data and save it into a .csv file, so they can later import
it into Excel.
I wrote and ran my query, and it worked very well. I exported the
result set (Save as ...) into a file.
However, when trying to import it into Excel I see a big problem. One
of the columns has data in it that contains commas. So, of course Excel
isn't importing the data correctly because it's splitting on the comma
for new rows when it's actually not a row.
Short of modifying all my data in the database(which can't be the best
solution), is there a simple way either in Sql Server or Excel where I
can export/import this data correctly?

CSV is evil. Try tab-delimited.
Thanks, that worked very well. Now I see another issue. One of my text
fields has data in it that must have a character(s) that is the same as
the record separator character (LF/CR ??). This is data users entered
in on the web so they could have put anything in here (This is a
project I'm taking over so I had no control over what data was input)
So, my import into Excel is splitting these thinking it should be a
new record.
Anyway to change the record separator in SQL server 2005 for exports?

Thanks,
m



Reply With Quote
  #4  
Old   
Ed Murphy
 
Posts: n/a

Default Re: Exporting out of SQL server -- comma in my column data - 08-27-2007 , 02:09 AM



Milagro wrote:

Quote:
Thanks, that worked very well. Now I see another issue. One of my text
fields has data in it that must have a character(s) that is the same as
the record separator character (LF/CR ??). This is data users entered in
on the web so they could have put anything in here (This is a project
I'm taking over so I had no control over what data was input)
So, my import into Excel is splitting these thinking it should be a new
record.
Anyway to change the record separator in SQL server 2005 for exports?
I think Excel will accept a field containing a line break if it's
quote-delimited. Try creating a view along the lines of

create view v_foo as
select field1,
'"' + replace(field2,'"','""') + '"' field2,
field3
from t_foo

and then exporting from that.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.