sqlserver表中的更新 [英] Updation in sqlserver table

查看:79
本文介绍了sqlserver表中的更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一张五排的桌子。我想用第一个记录的值更新最后四行。第一行包含主记录。我怎样才能做到这一点。 PLZ帮帮我



提前致谢

kunjammu

Hi,
I have a table with five rows. i want to update the last four rows with the values of first record. First row contain the master record. How can i do that. plz help me

Thanks in advance
kunjammu

推荐答案

对不起,我误解了这个问题。你可以这样做:



更新table1 set val =(从id1中选择top1 1 val)



你必须为每一栏做到这一点。如果你愿意的话,你可以一个一个完成。



更新table1 set val =(从id1中选择table1的前1个val),

val2 =(从id1的table1顺序中选择top 1 val2)等
Sorry, I misread the question. You can do this:

update table1 set val = ( select top 1 val from table1 order by id)

You''d have to do that for each column. You can do it all in one, if you like.

update table1 set val = ( select top 1 val from table1 order by id),
val2 = (select top 1 val2 from table1 order by id), etc


UPDATE TABLE_NAME SET
COL_NAME=(SELECT COL_NAME FROM TABLE_NAME WHERE RECNO= 1)


检查以下查询



Check following query

UPDATE myTable
SET
column1 = firstrow.column1,
column1 = firstrow.column1,
column1 = firstrow.column1
FROM
    (
    SELECT
    	column1,column2,column3
    FROM MyTable
    WHERE
    	RECNO=1
    ) firstrow
where RECNO<> 1





应该达到目的



希望有所帮助

Milind



That should serve the purpose

Hope that helps
Milind


这篇关于sqlserver表中的更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆