79539946

Date: 2025-03-27 20:23:06
Score: 1
Natty:
Report link

The "intermediate table" way mentionned by @Brad has several examples all over StackOverflow, but this may be what you would like to avoid when you say "I don't want to import data as VarChar because of the 6 M rows"

On the other hand, with the OPENROWSET you cited, once you have [defined a format file](https://learn.microsoft.com/en-us/sql/relational-databases/import-export/create-a-format-file-sql-server?view=sql-server-ver16&tabs=non-xml#a-create-a-non-xml-format-file-for-native-data] with your numeric as SQLVARCHAR,
they will appear as table columns which you can convert to FLOAT:

INSERT INTO dbo.table
SELECT …, CAST(REPLACE(fieldx, ',', '.') AS FLOAT), …
FROM OPENROWSET( BULK 'C:\mycsv.csv' ,
              FORMAT='CSV',
              FIRSTROW = 2,
              FIELDQUOTE='"',
              CODEPAGE='65001',
              FORMATFILE=''
) as a;
Reasons:
  • Blacklisted phrase (1): StackOverflow
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Brad
  • High reputation (-1):
Posted by: Guillaume Outters