SQL

Entries from April 2011

  • Homepage

Apr 13: T-SQL: Import csv in temp table

Seems pretty simple to do... Just execute a query like this one:

SELECT * INTO #TESTCSV
FROM OPENROWSET (
        'Microsoft.Jet.OLEDB.4.0',
        'Text;Database=C:\;HDR=YES',
        'SELECT * FROM test.csv')
 
In my case I was getting the following error message, which got me baffled for quite some time:
Msg 492, Level 16, State 1, Line 1
Duplicate column names are not allowed in result sets obtained through OPENQUERY and OPENROWSET. The column name "test#csv.NoName" is a duplicate.

This really didn't make any sense to me. There were no duplicate column names in the csv file and surely there were no columns named 'NoName', nor did I forget to name a column...

Then it came to me: what if UNICODE isn't parsed correctly? Maybe that could cause empty columns headers? The file was exported by ReportViewer and I had not looked at the encoding of the resulting csv file. Guess what!? The encoding was UNICODE. So, after saving the file in ANSI encoding, the query executed like a charm.
Posted by Twan Jacobs in SQL Comments: (0) Trackbacks: (0)
« previous page   (Page 1 of 1, totaling 1 entries)   next page »

Calendar

Back April '11 Forward
Mo Tu We Th Fr Sa Su
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  

Archives

  • May 2012
  • April 2012
  • March 2012
  • Recent...
  • Older...

Categories

  • XML BizTalk
  • XML C#
  • XML Daily Didst
  • XML Infra
  • XML SQL
  • XML WCF
  • XML WTF


All categories

Syndicate This Blog

  • XML RSS 2.0 feed
  • XML RSS 2.0 Comments

Blog Administration

Open login screen

Powered by

Serendipity PHP Weblog
 

Layout by Andreas Viklund | Serendipity template by Carl