S*********d 发帖数: 119 | 1 sql server 里面update一个table with a resultset,要根据被update的column来决
定怎么update,比如如果column1的value如果跟resultset的那个对应的value一样的话
,就不update这个column了
问题是除了CURSOR外,是否可以用一句UPDATE做呢 |
B*****g 发帖数: 34098 | 2 merge
【在 S*********d 的大作中提到】 : sql server 里面update一个table with a resultset,要根据被update的column来决 : 定怎么update,比如如果column1的value如果跟resultset的那个对应的value一样的话 : ,就不update这个column了 : 问题是除了CURSOR外,是否可以用一句UPDATE做呢
|
w*******e 发帖数: 1622 | 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做呢
|
S*********d 发帖数: 119 | 4 please shoot me a couple more words. thanks
【在 B*****g 的大作中提到】 : merge
|
S*********d 发帖数: 119 | 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...
|
B*****g 发帖数: 34098 | 6 Use merge function in SQL SERVER
http://msdn.microsoft.com/en-us/library/bb510625.aspx
【在 S*********d 的大作中提到】 : please shoot me a couple more words. thanks
|
S*********d 发帖数: 119 | 7 Thanks alot!
But..darn..this is new in 2008. I am still using sql2000..........I know.
【在 B*****g 的大作中提到】 : Use merge function in SQL SERVER : http://msdn.microsoft.com/en-us/library/bb510625.aspx
|
B*****g 发帖数: 34098 | 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.
|
j*****n 发帖数: 1781 | 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
|