由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 请教SQL
相关主题
SQL aggregate multiple columns in ACCESShow to get the product for a column
SQL Server Update Query - non-unique value请教SQL server的一个programming的问题,谢谢
SQL 2000 create index 問題interview question (SQL)
请问可不可以在sql语句中用序号表示columnSQL Server - how to obtain data type name
请问数据表里筛选变量名的写法每天只工作1小时的日子也挺没劲的。
Oracle Group and Index question请问这个update query有什么问题?
有趣的Join问题,源于SQL和SAS比较。MS SQL Group By Question
ask for help with a simple query!!!求解释
相关话题的讨论汇总
话题: update话题: sql话题: resultset话题: tableb话题: tablea
进入Database版参与讨论
1 (共1页)
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

1 (共1页)
进入Database版参与讨论
相关主题
求解释请问数据表里筛选变量名的写法
这2个query哪个快点,为啥Oracle Group and Index question
Question for SQL statment有趣的Join问题,源于SQL和SAS比较。
问个数据库问题ask for help with a simple query!!!
SQL aggregate multiple columns in ACCESShow to get the product for a column
SQL Server Update Query - non-unique value请教SQL server的一个programming的问题,谢谢
SQL 2000 create index 問題interview question (SQL)
请问可不可以在sql语句中用序号表示columnSQL Server - how to obtain data type name
相关话题的讨论汇总
话题: update话题: sql话题: resultset话题: tableb话题: tablea