如何在SQL Server中批量插入派生列?(How to bulk insert with derived columns in SQL Server?)
新手到SQL Server!
我尝试在SQL Server中执行批量插入。 我有以下名为
input.csv
csv文件:NO,Name,age,Reference,dateTime,Category 1,Stack@mail,23,Kiop,2017-03-02T12:23:00,D 2,OverEnd@Yahoo,22,CSK,2017-030-03T12:23:00,I
在该CSV文件中,我必须使用
BulkInsert
将其移动到SQL Server中,进入下面的表模式:create table BulkInsertTemp ( no int, name nvarchar(50), age int, Ref nvarchar(30), currentDatetime datetime, Category nvarchar(40) )
现在我需要在SQL中存储如下:
no Name age Ref currentDatetime category -------------------------------------------------------- 1 Stack 23 Kiop 2017-03-02 12:23:00 D 2 OverEnd 22 CSK 2017-03-03 12:23:00 I
我只是尝试下面的查询另一个表进入SQL Server。
create table bulkInsert(no varchar(50),name varchar(50)); BULK INSERT bulkInsert FROM 'C:\MyInput\BulkInsert\BulkInsertData.txt' WITH (FIRSTROW = 1, ROWTERMINATOR = '\n', FIELDTERMINATOR = ',', ROWS_PER_BATCH = 10000)
如果不需要修改数据,我的查询就有效。
但是在
input.csv
我必须更改列值,例如name是否为“Stack @ mail”,以便在SQL中存储为“Stack”我是一个新的批量插入选项,所以我不知道如何从现有列派生列。
有人,请指导我解决我的要求吗?
Newbie to SQL Server!
I try to perform bulk insert into SQL Server. I have the following csv file named
input.csv
:NO,Name,age,Reference,dateTime,Category 1,Stack@mail,23,Kiop,2017-03-02T12:23:00,D 2,OverEnd@Yahoo,22,CSK,2017-030-03T12:23:00,I
In that CSV file, I have to move that into SQL Server using
BulkInsert
into below table schema:create table BulkInsertTemp ( no int, name nvarchar(50), age int, Ref nvarchar(30), currentDatetime datetime, Category nvarchar(40) )
Now I need to store in SQL like:
no Name age Ref currentDatetime category -------------------------------------------------------- 1 Stack 23 Kiop 2017-03-02 12:23:00 D 2 OverEnd 22 CSK 2017-03-03 12:23:00 I
I just tried below query for another one table to move into SQL Server.
create table bulkInsert(no varchar(50),name varchar(50)); BULK INSERT bulkInsert FROM 'C:\MyInput\BulkInsert\BulkInsertData.txt' WITH (FIRSTROW = 1, ROWTERMINATOR = '\n', FIELDTERMINATOR = ',', ROWS_PER_BATCH = 10000)
My query worked if there is no need for modifying data.
But in
input.csv
I have to change column values such as if name is "Stack@mail" to be store as "Stack" in SQLI am a new one to bulk insert option so I don't know how to derive columns from existing ones.
Anyone, please guide me to solve my requirement?
原文:https://stackoverflow.com/questions/44062020
最满意答案
这不应该显示b中的值吗?
你正在调用(在
b
的上下文中)一个对此无效的函数。 该函数在window
(默认对象)的上下文中调用callback
(它是a.showVal
的副本)。Shouldn't this display the value in b?
You are calling (in the context of
b
) a function which does nothing withthis
. That function callscallback
(which is a copy ofa.showVal
) in the context ofwindow
(the default object).
相关问答
更多-
为什么我的'this'不会在每个循环中改变内部jQuery中的上下文?(Why is my 'this' not changing context inside inner jQuery each loop?)[2022-11-09]
当您进入新的嵌套函数时, this改变意义。 当您调用$()来创建新元素时,它不会改变含义。 所以马上就到了 $.each(obj, function(index, dataObj) { this是您循环的当前对象。 到达这里后: .live("click",function(event) { // <------ inside of nested function openVideo($(event.target).data(dataID)); }) this是您单击的元素。 但是打电话 ... -
dc就像一个未绑定的实例方法。 您可以使用Function.prototype.bind创建绑定到d的新函数( .bind的第一个参数是this参数): var e = d.c.bind(d); 或者用d作为this参数来调用e : e.call(d); d.c is like an unbound instance method. You can use Function.prototype.bind to create a new function that's bound to d (the fi ...
-
在javascript中更改函数的上下文的目的是什么?(What is the purpose of changing a function's context in javascript?)[2021-05-26]
我认为.apply , .apply和.bind ,调用可能是最少使用的 - 但所有3种方法都用于更改函数的范围。 在我看来, .bind是最有用的,因为它返回一个带有强制范围的函数,其中.apply和.apply会立即执行一个函数。 如果您想在保持对象范围的同时使用某些方法作为事件处理程序,那么您将使用bind,否则范围将更改为我们将事件绑定到的元素。 var singleton = { prop: 'howdy do!', method: function() { this.doSom ... -
call是为Function对象定义的Function 。 要call的第一个参数是在被调用函数内引用的对象。 在没有任何特定上下文的情况下调用fn() , this指的是全局上下文或浏览器环境中的window对象。 相同的规则适用于全局范围中的值。 所以在fn() == this) , this指的是全局对象。 但是,当在某个其他对象的上下文中调用它时,就像在fn.call(object) , this里面的fn引用了object 。 fn.call(object)根本不修改或赋予object任何东西。 ...
-
为什么我的变量不变?(Why isn't my variable changing?)[2023-07-25]
我是否使用了switch语句错误,或者我没有正确解析该值? 正是这样。 按钮的值是字符串,但是switch语句对数字有效。 case语句使用严格相等,包括类型。 因此要么将值解析为数字,要么在您的情况下使用字符串文字。 目前,您的代码将始终达到default情况。 我使用全局变量的唯一原因是因为我不太熟悉javascript中的作用域如何工作,所以我认为这种方式可能更容易。 实际上非常简单:所有函数声明,参数声明和var声明都限定在包含它们的函数中。 你真的应该在这里使用局部变量。 顺便说一句,你真的应该移 ... -
Javascript对象上下文(Javascript Object context)[2023-06-02]
您将调用上下文(使用this关键字 )与变量scope以及对象属性混淆。 回答你的问题: 不 ,对象没有范围。 只有函数有一个scope属性,当调用它们时,它将初始化变量对象的作用域链。 由于height函数范围内没有名称name变量,因此它解析为undefined (甚至是参考错误)。 You're confusing the call context (with the this keyword) with the variable scope, and with object properties. ... -
javascript中的上下文(Context in javascript)[2023-11-14]
那么,第一个例子中this === window的原因和第二个例子中的this === shuriken都与创建这些函数的位置有关。 请注意,当您在对象外部定义shuirken.toss时, this指向窗口对象。 当你用new调用katana时, this指向新创建的对象。 Well, the reason this === window in the first example and this === shuriken in the second example all has to do with ... -
您可以做的最接近的事情是使用with语句屏蔽全局变量。 var myGlobalContext = {bar: "foo"}; with(myGlobalContext) { console.log(bar); } 这与更改全局上下文不同,因为myGlobalContext找不到的其他全局变量仍然存在。 一般来说, with语句很糟糕 ,但听起来你的用例可能是有意义的。 The closest thing you can do is mask the global variables using ...
-
这不应该显示b中的值吗? 你正在调用(在b的上下文中)一个对此无效的函数。 该函数在window (默认对象)的上下文中调用callback (它是a.showVal的副本)。 Shouldn't this display the value in b? You are calling (in the context of b) a function which does nothing with this. That function calls callback (which is a copy of ...
-
当我们创建一个对象时,它是否创建了一个执行上下文? 没有。 因为在调用函数时会创建执行上下文。 这是事实,但创建一个对象与调用一个函数是不同的。 如果没有,那么对象就像实际执行上下文中的其他变量一样? 该对象存在于内存中,对它的引用存在于您存储它的任何变量或属性中。如果将它存储在变量中,该变量将保存在与声明变量的执行上下文相关联的词汇环境对象中。 具体示例可能会有所帮助: function foo() { var n = 42; var o = {}; console.log(n, ...