home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 18,681 of 19,505   
   Erland Sommarskog to Cathy   
   Re: MSSMSE - Export results to CSV   
   22 Jun 12 20:38:30   
   
   From: esquel@sommarskog.se   
      
   Cathy (Cathy@Nospam.com) writes:   
   > I could use the wizard, but the idea is to get a script that I can run   
   > against many databases, to export the results individually whilst running.   
   > Saving file data manually is almost easier and quicker than using the   
   > wizard, unless I am missing a trick.   
   >   
   > ***RESULT of BCP***   
   > 1,Beverages,Soft drinks, coffees, teas, beers, and ales   
   > 2,Condiments,Sweet and savory sauces, relishes, spreads, and seasonings   
   > 3,Confections,Desserts, candies, and sweet breads   
   > 4,Dairy Products,Cheeses   
   > 5,Grains/Cereals,Breads, crackers, pasta, and cereal   
   > 6,Meat/Poultry,Prepared meats   
   > 7,Produce,Dried fruit and bean curd   
   > 8,Seafood,Seaweed and fish   
      
   OK. This can be arranged with a format file:   
      
   9.0   
   3   
   1 SQLCHAR 0 0 ","      1 Description  ""   
   2 SQLCHAR 0 0 ",\""    2 CategoryName Latin1_General_CI_AS   
   3 SQLCHAR 0 0 "\"\r\n" 3 Description  Latin1_General_CI_AS   
      
   Then replace "-c -t," in the command with "-f format.fmt".   
      
   An alternative is to run the query as   
      
   SELECT CategoryID, CategoryName, quotename(Description, '"')   
   FROM  [Northwind].[dbo].[Categories]   
      
   Actually, this is better, because this will also handle double quotes   
   in the data.   
      
   --   
   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   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca