首页 \ 问答 \ 如何在SQL Server中批量插入派生列?(How to bulk insert with derived columns in SQL Server?)

如何在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 SQL

I 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
更新时间:2022-06-19 12:06

最满意答案

这不应该显示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 a.showVal) in the context of window (the default object).

相关问答

更多
  • 当您进入新的嵌套函数时, 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 ...
  • 我认为.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任何东西。 ...
  • 我是否使用了switch语句错误,或者我没有正确解析该值? 正是这样。 按钮的值是字符串,但是switch语句对数字有效。 case语句使用严格相等,包括类型。 因此要么将值解析为数字,要么在您的情况下使用字符串文字。 目前,您的代码将始终达到default情况。 我使用全局变量的唯一原因是因为我不太熟悉javascript中的作用域如何工作,所以我认为这种方式可能更容易。 实际上非常简单:所有函数声明,参数声明和var声明都限定在包含它们的函数中。 你真的应该在这里使用局部变量。 顺便说一句,你真的应该移 ...
  • 您将调用上下文(使用this关键字 )与变量scope以及对象属性混淆。 回答你的问题: 不 ,对象没有范围。 只有函数有一个scope属性,当调用它们时,它将初始化变量对象的作用域链。 由于height函数范围内没有名称name变量,因此它解析为undefined (甚至是参考错误)。 You're confusing the call context (with the this keyword) with the variable scope, and with object properties. ...
  • 那么,第一个例子中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, ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)