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

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Number of working days between two dates(两个日期之间的工作日数)
How do I use dateadd to get the first day of last year?(如何使用 dateadd 获取去年的第一天?)
SQL- Count occurrences of a specific word within all stored procedures(SQL- 计算所有存储过程中特定单词的出现次数)
SQL query to make a column of numbers a string(使一列数字成为字符串的 SQL 查询)
T-SQL: Best way to replace NULL with most recent non-null value?(T-SQL:用最新的非空值替换 NULL 的最佳方法?)
Count days in date range with set of exclusions which may overlap(使用一组可能重叠的排除项计算日期范围内的天数)