Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-sqlserver > #1154

Re: MSSMSE - Export results to CSV

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From Erland Sommarskog <esquel@sommarskog.se>
Newsgroups comp.databases.ms-sqlserver
Subject Re: MSSMSE - Export results to CSV
Date Sat, 23 Jun 2012 11:28:43 +0200
Organization Erland Sommarskog
Lines 31
Message-ID <XnsA07B74C453D57Yazorman@127.0.0.1> (permalink)
References <5oudnZwNaMRT-37SnZ2dnUVZ8g-dnZ2d@bt.com> <XnsA079F0DCCBB92Yazorman@127.0.0.1> <FpednYO2bofgOn7SnZ2dnUVZ8kydnZ2d@bt.com> <XnsA07A7596B3550Yazorman@127.0.0.1> <1JudnbRjP9BoMnnSnZ2dnUVZ8lmdnZ2d@bt.com> <XnsA07AD1FB0B573Yazorman@127.0.0.1> <qcWdnUB-Rv_uennSnZ2dnUVZ7oKdnZ2d@bt.com>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252
Content-Transfer-Encoding 8bit
Injection-Info mx04.eternal-september.org; posting-host="nBFDv6s1VJQDuF1w6hpX2A"; logging-data="4100"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Iv8y/5C/OylNnrtTUmUlp"
User-Agent Xnews/2006.08.24 Mime-proxy/2.1.c.0 (Win32)
Cancel-Lock sha1:PeCkkAClIAvHhOwF096D5aQzK5Q=
Xref csiph.com comp.databases.ms-sqlserver:1154

Show key headers only | View raw


Cathy (Cathy@Nospam.com) writes:
> This is brilliant
>> SELECT CategoryID, CategoryName, quotename(Description, '"')
>> FROM  [Northwind].[dbo].[Categories]
> 
> Only problem I have now is that bcp reads the quote as the end of the 
> command. Is there a way to escape this?
> 
> bcp "SELECT CategoryID, CategoryName, quotename(Description, '"')FROM 
> [Northwind].[dbo].[Categories]" queryout outputfile.csv
 
Well, not BCP but the command-line parser. I should have thought about 
that, sorry. I think that you can use \ to escape the quote:

bcp "SELECT CategoryID, CategoryName, quotename(Description, '\"')FROM 
[Northwind].[dbo].[Categories]" queryout outputfile.csv

But it may be simpler to use

   quotename(Description, char(34))

instead, and evading the problem that way.


-- 
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx

Back to comp.databases.ms-sqlserver | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

MSSMSE - Export results to CSV "Cathy" <Cathy@Nospam.com> - 2012-06-21 19:24 +0100
  Re: MSSMSE - Export results to CSV Erland Sommarskog <esquel@sommarskog.se> - 2012-06-21 23:40 +0200
    Re: MSSMSE - Export results to CSV "Cathy" <Cathy@Nospam.com> - 2012-06-22 00:00 +0100
      Re: MSSMSE - Export results to CSV Erland Sommarskog <esquel@sommarskog.se> - 2012-06-22 11:33 +0200
        Re: MSSMSE - Export results to CSV "Cathy" <Cathy@Nospam.com> - 2012-06-22 18:48 +0100
          Re: MSSMSE - Export results to CSV Erland Sommarskog <esquel@sommarskog.se> - 2012-06-22 20:38 +0200
            Re: MSSMSE - Export results to CSV "Cathy" <Cathy@Nospam.com> - 2012-06-22 22:45 +0100
              Re: MSSMSE - Export results to CSV Erland Sommarskog <esquel@sommarskog.se> - 2012-06-23 11:28 +0200
                Re: MSSMSE - Export results to CSV "Cathy" <Cathy@Nospam.com> - 2012-06-23 23:49 +0100

csiph-web