English 中文(简体)
利用BULK INSERT绘制一栏图
原标题:Using BULK INSERT to map columns

我有一份CSV档案,有600万行。 每一行均采用相同格式g/g。

I,h,q,q,3,A,5,Q,3,[,5,Q,8,c,3,N,3,E,4,F,4,g,4,I,V,9000,0000001-100,G9999999990001800000000000001,G9999999990000001100PDNELKKMMCNELRQNWJ010, , , , , , ,D,Z

页: 1

第1栏应为CSV的27栏,第2栏应为CSV档案的全线。

我试图建立一个格式文件,但无法运作。

甚至有可能进行这种测绘?

在这方面,我已经:

BULK INSERT Staging FROM  C:Data.txt  
   WITH 
   (
      FIELDTERMINATOR = , ,
      ROWTERMINATOR = 
 ,
      KEEPNULLS,
      formatfile= C:format.fmt 
   )

这是我的格式文件。

9.0
2
1       SQLCHAR       0       40     ","     27     Col27               SQL_Latin1_General_CP1_CI_AS
2       SQLCHAR       0       200     "
"  1     Col1               SQL_Latin1_General_CP1_CI_AS

相比之下,我是在库特工作,有2名35名官员。

最佳回答

你们可以通过多种方式战胜这一nut子,但我这样做的方式是,通过动态将世卫组织的LE csv文件加进一个温桌:

CREATE TABLE #BulkLoadData(
    RecordData NVARCHAR(max)
)


SET @SQL =  BULK INSERT #BulkLoadData FROM     + @SourceFileFullPath +      
SET @SQL = @SQL +  WITH (FORMATFILE =     + @UPXInputFileBulkLoadFormat +  UPXInputFileBulkLoadFormat.xml  , TABLOCK, ROWS_PER_BATCH = 2500 )  

EXECUTE (@SQL)

然后,你可将数据插入目标表,如:

INSERT INTO dbo.TargetTable
SELECT dbo.fnParseString(27,  , , RecordData), RecordData

你们需要发挥类似的作用:

CREATE FUNCTION [dbo].[fnParseString]
(
    @Section SMALLINT,
    @Delimiter CHAR,
    @Text VARCHAR(MAX)
)
RETURNS VARCHAR(8000)
AS

BEGIN
DECLARE @startindex NUMERIC(18,0),
     @length NUMERIC(18,0),
     @FieldPosition INT

 SET @FieldPosition = ABS(@Section) - 1
 SET @startindex = 0


 WHILE @FieldPosition != 0
 BEGIN
    SET @FieldPosition = @FieldPosition - 1
     SET @startindex = CHARINDEX(@Delimiter, @Text, @startindex + 1) 
 END     


 SET @Text = SUBSTRING(@Text, @startindex + 1, LEN(@Text) - @startindex)
 SET @Text = SUBSTRING(@Text, 0, CHARINDEX(@Delimiter, @Text))

 RETURN @Text
END

希望帮助! 如果你们需要帮助填写格式文件,我就知道。

格式文件内容如下:

<?xml version="1.0"?>
<BCPFORMAT xmlns="http://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <RECORD>
    <FIELD ID="1" xsi:type="CharTerm" TERMINATOR="
" MAX_LENGTH="8000" COLLATION="SQL_Latin1_General_CP1_CI_AS"/>
  </RECORD>
  <ROW>
    <COLUMN SOURCE="1" NAME="RecordData" xsi:type="SQLVARYCHAR"/>
  </ROW>
</BCPFORMAT>
问题回答

暂无回答




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签