avatar
S*d
1
sql server 里面update一个table with a resultset,要根据被update的column来决
定怎么update,比如如果column1的value如果跟resultset的那个对应的value一样的话
,就不update这个column了
问题是除了CURSOR外,是否可以用一句UPDATE做呢
avatar
B*g
2
merge

【在 S*********d 的大作中提到】
: sql server 里面update一个table with a resultset,要根据被update的column来决
: 定怎么update,比如如果column1的value如果跟resultset的那个对应的value一样的话
: ,就不update这个column了
: 问题是除了CURSOR外,是否可以用一句UPDATE做呢

avatar
w*e
3
using CASE WHEN....THEN...ELSE...

【在 S*********d 的大作中提到】
: sql server 里面update一个table with a resultset,要根据被update的column来决
: 定怎么update,比如如果column1的value如果跟resultset的那个对应的value一样的话
: ,就不update这个column了
: 问题是除了CURSOR外,是否可以用一句UPDATE做呢

avatar
S*d
4
please shoot me a couple more words. thanks

【在 B*****g 的大作中提到】
: merge
avatar
S*d
5
yah, thought about that.
Here is a tentative statement
update tableA
set columnA1 =
case
when columnA1 <> tableB.columnB1 then tableB.columnB1
end,
columnA2=
case
when columnA2 <> tableB.columnB2 then tableB.columnB2
end,
inner join tableB on
tableA.pk=tableB.pk
the problem is for the columns of tableA's that don't equal to table tableB'
s, they are still updated........with Null value, which isn't required.

【在 w*******e 的大作中提到】
: using CASE WHEN....THEN...ELSE...
avatar
B*g
8
should be in 2005, not in 2000.

【在 S*********d 的大作中提到】
: Thanks alot!
: But..darn..this is new in 2008. I am still using sql2000..........I know.

avatar
j*n
9
set ansi_nulls off

【在 S*********d 的大作中提到】
: yah, thought about that.
: Here is a tentative statement
: update tableA
: set columnA1 =
: case
: when columnA1 <> tableB.columnB1 then tableB.columnB1
: end,
: columnA2=
: case
: when columnA2 <> tableB.columnB2 then tableB.columnB2

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。