Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > microsoft.public.sqlserver.programming > #31316
| From | Erland Sommarskog <esquel@sommarskog.se> |
|---|---|
| Newsgroups | microsoft.public.sqlserver.programming |
| Subject | Re: Bulk Insert Erratic insert order. Any Help Greatly Appreciated. |
| Date | 2017-04-29 10:25 +0200 |
| Organization | Erland Sommarskog |
| Message-ID | <XnsA7666A03B9350Yazorman@127.0.0.1> (permalink) |
| References | <bca21819-f64b-4e56-8958-55a765d92575@2g2000yqk.googlegroups.com> <f44a9b6e-bee0-4ca1-9d03-c66ff66d3c2f@googlegroups.com> |
(deanseawa@gmail.com) writes:
> As long as your file is a text file, with each row terminated with a
> standard CRLF, this approach should work (tested Sql2008):
>
> ---------------------------------
> Declare @X xml;
> ---------------------------------
> SELECT X=Cast('<X>' + Replace([BulkColumn], Char(13)+Char(10), > '</X><X>')+'</X>' as XML)
> FROM OPENROWSET (BULK N'\\FileServer\ImportFolder\ImportFile_20170120.csv',
> SINGLE_CLOB) T
> ---------------------------------
> SELECT [Record].[X].query('.').value('.','varchar(max)') [Record]
> ,ROW_NUMBER() OVER (ORDER BY (SELECT 100)) [ID]
> Into #TEMP
> FROM @X.nodes('X') [Record](X);
> ---------------------------------
>
Note that this will fall flat if the file includes characters that are
special to XML.
Back to microsoft.public.sqlserver.programming | Previous | Next — Previous in thread | Find similar
Re: Bulk Insert Erratic insert order. Any Help Greatly Appreciated. deanseawa@gmail.com - 2017-04-28 15:39 -0700 Re: Bulk Insert Erratic insert order. Any Help Greatly Appreciated. Erland Sommarskog <esquel@sommarskog.se> - 2017-04-29 10:25 +0200
csiph-web