用SQL server中另一个表中相同列的值替换一列

用SQL server中另一个表中相同列的值替换一列,sql,sql-server,Sql,Sql Server,我有两张桌子,一张大一张小。两者都包含列ID和EffectiveDate 较大的表比较小的表有更多的其他列,当然也有更多的行 在两个表的ID相同的条件下,小表中的EffectiveDate列早于大表。我想用小表中EffectiveDate列的值替换大表中的EffectiveDate 我该怎么办?似乎是一个非常基本的SQL查询 UPDATE bt SET EffectiveDate = st.EffectiveDate FROM dbo.BiggerTable bt INNER JOIN dbo.

我有两张桌子,一张大一张小。两者都包含列
ID
EffectiveDate

较大的表比较小的表有更多的其他列,当然也有更多的行

在两个表的
ID
相同的条件下,小表中的
EffectiveDate
列早于大表。我想用小表中
EffectiveDate
列的值替换大表中的
EffectiveDate


我该怎么办?

似乎是一个非常基本的SQL查询

UPDATE bt
SET EffectiveDate = st.EffectiveDate
FROM dbo.BiggerTable bt
INNER JOIN dbo.SmallerTable st ON bt.ID = st.ID
-- maybe you also need this condition, if not *ALL* EffectiveDate values in the 
-- smaller table are indeed before the values in the bigger table
WHERE st.EffectiveDate < bt.EffectiveDate
更新bt
SET EffectiveDate=st.EffectiveDate
来自dbo.BiggerTable bt
bt.ID=st.ID上的内部联接dbo.SmallerTable st
--也许您还需要这个条件,如果不是
--较小的表确实在较大表中的值之前
其中st.EffectiveDate
编写代码将是一个很好的开始。表中的那些“东西”是列(而不是变量),但我相信他也需要
根据他的评论,st.EffectiveDate
。@JiggsJedi:可能-我不清楚是否已经是这样了,对于所有行(阅读文章时…)我听到了,它的措辞很糟糕。非常感谢你!我一周前开始使用SQL。您的查询很简单,可以完成任务!!!!!!!