简体   繁体   中英

How to SQL-query this excel table with accented names of the columns in header?

Summary: Using the Jet.OLEDB provider and the SQL query, I cannot extract some columns from the Excel table. The reason probably is that the header text contains some accented characters. Is it possible to refer the columns technically? Something like the column K or C12 instead of using the text of the header...

Details: Actually, the specific Excel document can be downloaded from http://www.sukl.cz/file/80129_1_1 -- the document name is DistribuceLP_2015_01.xls (see later the prescription). It contains some publicly available statistics that are to be downloaded and extracted.

After downloading and saving the file, I did extract some columns without problems;

I have a tool that takes a connection string, the destination directory, and series of the SQL command + target table name. It generates plain old DBF tables with the extracted content. The text file with description of the transformation looks like this -- so you can see the the connection string and the SELECT query. The sheet was renamed for testing to A :

connection:Provider=Microsoft.Jet.OLEDB.4.0;Data source=d:\download\DistribuceLP_2015_01.xls;Extended Properties="Excel 8.0;HDR=Yes;"
outputdir:.
----------------
test
SELECT
  [Období] AS obdo,
  [Typ odběratele] AS typodb, 
  ATC7,
  [Kód SÚKL] AS kodsukl,
  [Název přípravku] AS nazev,
  [Doplněk názvu] AS baleni,
  [Držitel registračního rozhodnutí] AS drr,
  [Země] AS zeme,
  [Typ pohybu] AS pohyb,
  [Počet balení/M] AS pocbal,
  [Cena za balení bez obch. přirážky a DPH] AS cenabal,                -- !!!
  [Celkem finance za všechna balení bez obch. přirážky a DPH] AS cena, -- !!!
  [Počet definovaných denních dávek/balení] AS dendavek,
  [Počet denních definovaných dávek/balení celkem] AS davek,
  [Způsob výdeje] AS vydej
FROM [A$]

It almost works. If I remove the lines marked by -- !!! , the extraction goes fine. The two marked lines cause an error. I suspect the accented letter ř , or possibly the dot in the text.

Do you have some experience with a similar case?

I believe you need to use a collation with accent insensitivity as your collation settings might be different in your target database:

SELECT
  [Období] COLLATE Latin1_general_CI_AI AS obdo,
  [Typ odběratele] COLLATE Latin1_general_CI_AI AS typodb, 
  ATC7,
  [Kód SÚKL] COLLATE Latin1_general_CI_AI AS kodsukl,
  [Název přípravku] COLLATE Latin1_general_CI_AI AS nazev,
  [Doplněk názvu] COLLATE Latin1_general_CI_AI AS baleni,
  [Držitel registračního rozhodnutí] COLLATE Latin1_general_CI_AI AS drr,
  [Země] COLLATE Latin1_general_CI_AI AS zeme,
  [Typ pohybu] AS pohyb,
  [Počet balení/M]  COLLATE Latin1_general_CI_AI AS pocbal,
  [Cena za balení bez obch. přirážky a DPH] COLLATE Latin1_general_CI_AI AS cenabal,                -- !!!
  [Celkem finance za všechna balení bez obch. přirážky a DPH] COLLATE Latin1_general_CI_AI AS cena, -- !!!
  [Počet definovaných denních dávek/balení] COLLATE Latin1_general_CI_AI AS dendavek,
  [Počet denních definovaných dávek/balení celkem] COLLATE Latin1_general_CI_AI AS davek,
  [Způsob výdeje] COLLATE Latin1_general_CI_AI AS vydej
FROM [A$]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM