将列值从一个 database.table 复制到另一个 database

copy column value from one database.table to another database.table(将列值从一个 database.table 复制到另一个 database.table)

本文介绍了将列值从一个 database.table 复制到另一个 database.table的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们保持简短和甜蜜

我想这样做(我现在失败了很多次,一次尝试甚至用空格更新了行):

I want to do this (I've failed numerous times now, and one attempt even updated the Row with blanks):

UPDATE Database2.Table1 
SET (Database2.Table1.Column1, Database2.Table1.Column2, Database2.Table1.Column3) 
VALUES 
   (Database1.Table1.Column1, Database1.Table1.Column2, Database1.Table1.Column3)
WHERE Database2.Table1.Column1 = Database1.Table1.Column1

这两个已经包含相同的值,但其他 2 列没有,这就是我希望通过此查询更改的内容..

These two already contain the same value, but the other 2 columns do not, and that is what I wish to change with this query..

每个表的外观如下:

Database1.Table1

[id]
[name]
[applicationdate]
[startdate]
[shortdescription]
[longdescription]
[displayimg]
[contact]
[website]
[created]
[urlbase]
[site]
[keywords]
[type]
[location]

Database2.Table1

[id]
[name]
[applicationdate]
[startdate]
[content]
[keywords]
[customerid]
[urlbase]
[shortdescription]
[meta]
[type]
[site]
[searchurlbase]
[lang]
[educationlength]
[locations]
[educationwebsite]
[contact]
[tags]
[educationtypes]
[created]
[category]

非常感谢您的帮助,感谢您的时间:)

Any help is greatly appreciated, thank you for your time :)

对不起,如果它没有任何意义,我在试图解释我遇到的问题时很容易感到困惑

Sorry if it doesn't make any sense, I easily get confused when trying to explain problems I'm having

推荐答案

UPDATE dest
  SET column2 = src.column2,
      column3 = src.column3
FROM Database2.dbo.Table1 AS dest 
INNER JOIN Database1.dbo.Table1 AS src
ON dest.column1 = src.column1;

鉴于您的整理问题,您可以在等式运算中指定整理.不知道哪一方给出了问题,并假设您不关心区分大小写:

Given your collate problem, you can specify collate in the equality operation. Having no idea which side is giving the problem, and assuming you don't care about case sensitivity:

UPDATE dest
  SET column2 = src.column2,
      column3 = src.column3
FROM Database2.dbo.Table1 AS dest 
INNER JOIN Database1.dbo.Table1 AS src
ON dest.column1 COLLATE Finnish_Swedish_CI_AS
 = src.column1  COLLATE Finnish_Swedish_CI_AS;

如果您关心区分大小写,请将两个子句更改为 _CS_AS_ 一个.

If you care about case sensitivity, then change both clauses to the _CS_AS_ one.

这篇关于将列值从一个 database.table 复制到另一个 database.table的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:将列值从一个 database.table 复制到另一个 database

基础教程推荐