我正在尝试上传虚拟数据,这将有助于上传更大的文件。 虚拟数据如下:
var oData = {
"data": [
{
"name": "Example1",
"value": "16.505406"
},
{
"name": "Example2",
"value": "6.65465"
},
{
"name": "Example3",
"value": "89.56456"
}
]
};
var oModel = new JSONModel(oData);
this.getView().setModel(oModel);
<MultiComboBox
selectionFinish="onBoxFinish"
items="{/data}">
<core:Item
key="{name}"
text="{value}">
</core:Item>
</MultiComboBox>
迫使我通过+---------+-------+----------+------------+------+---------------------------------------------------------------+
| Name | Class | Subject | ExamDate | Mark | Description |
+---------+-------+----------+------------+------+---------------------------------------------------------------+
| Prabhat | 4 | "Math" | 02/10/2013 | 25 | "Test data for prabhat.' |
| Murari | 5 |"Science" | 02/11/2013 | 24 | "Test data for his's test, where we can test 2nd ROW, Test." |
| sanjay | 4 | "Science"| | 25 | "Test Only." |
| xyz | 5 |"Science,"| | | "" |
+---------+-------+----------+------------+------+---------------------------------------------------------------+
上传数据的问题是,我不想在上传后将BULK INSERT
列的数据类型更改为ExamDate
。
因此,我创建了一个表,并使用以下代码通过批量插入上传了数据:
date
上面的查询给出错误,如下CREATE TABLE test_data (
[Name] NVARCHAR(MAX) NULL,
[Class] NVARCHAR(MAX) NULL,
[Subject] NVARCHAR(MAX) NULL,
[ExamDate] date NULL,
[Mark] INT NULL,
[Description] NVARCHAR(MAX) NULL
)
BULK INSERT test_data
FROM 'D:\TP - Churn\text.csv'
WITH
(
FIRSTROW = 2,
FORMAT = 'CSV',
FIELDQUOTE = '"',
FIELDTERMINATOR = '"\"', --CSV field delimiter
ROWTERMINATOR = '\n', --Use to shift the control to next row
TABLOCK
)
。
删除Incorrect syntax near 'FORMAT'
行并执行将产生相同的错误,但是这次是FORMAT = 'CSV'
。
引入FIELDQUOTE
的目的是要处理最后一行,在FIELDQUOTE = '"'
列中,科学之后有subject
。 csv中的此项类似于,
。
根据Incorrect syntax near format in BULK INSERT?,我认为在使用SQL Server 2016时不能使用"Science,"
。
编辑: 到目前为止,我已经使用以下格式文件设法做到这一点:
如果那是真的,那么我们如何处理上述问题?
FIELDQUOTE
结果如下:
11.0
6
1 SQLCHAR 0 8000 "," 1 Name SQL_Latin1_General_CP1_CI_AS
2 SQLCHAR 0 40 "," 2 Class SQL_Latin1_General_CP1_CI_AS
3 SQLCHAR 0 40 "\"," 3 Subject SQL_Latin1_General_CP1_CI_AS
4 SQLCHAR 0 40 "," 4 ExamDate SQL_Latin1_General_CP1_CI_AS
5 SQLCHAR 0 40 "," 5 Mark SQL_Latin1_General_CP1_CI_AS
6 SQLCHAR 0 1000 "\"\r\n" 6 Description SQL_Latin1_General_CP1_CI_AS
+---------+-------+-----------+------------+------+-------------------------------------------------------------+
| Name | Class | Subject | ExamDate | Mark | Description |
+---------+-------+-----------+------------+------+-------------------------------------------------------------+
| Prabhat | 4 | "Math | 10/02/2013 | 25 | "Test data for prabhat. |
| Murari | 5 | "Science | 11/02/2013 | 24 | "Test data for his's test, where we can test 2nd ROW, Test. |
| sanjay | 4 | "Science | NULL | 25 | "Test Only. |
| xyz | 5 | "Science, | NULL | NULL | " |
+---------+-------+-----------+------------+------+-------------------------------------------------------------+
和Subject
列中开头的引号均未删除。此外,最后一行和最后一列为空,但结果不是NULL。
在记事本中打开文件的结果:
Description