有个表Test
ID Name PID PName
1 a null null
2 b null null
3 c null null
4 d 1 a
5 e 1 a
6 f 3 c
现在我要不PID为1的记录的PID 和 PName 换成ID为2的ID 和 Name 即得到
ID Name PID PName
1 a null null
2 b null null
3 c null null
4 d 2 b
5 e 2 b
6 f 3 c
ID Name PID PName
1 a null null
2 b null null
3 c null null
4 d 1 a
5 e 1 a
6 f 3 c
现在我要不PID为1的记录的PID 和 PName 换成ID为2的ID 和 Name 即得到
ID Name PID PName
1 a null null
2 b null null
3 c null null
4 d 2 b
5 e 2 b
6 f 3 c
解决方案 »
- 关于 ASP.NET 程序更新
- 类似于DevExpress的GAC在 虚拟主机的部署问题
- 获取访问人IP问题?
- 如何将gridview的一列的值作为参数加入到ShowModelDG(ctl) 中,ShowModelDG(ctl,“参数”),下面取的时候该如何取呢?
- 急~~~~~~~~~~~~~~~~~~~"SQL命令未正确结束"为什么????
- 关于数字证书签名与验证
- 请教:: 怎么对一个多级的XML读取成多个关联的GridView ,,并对其添加删除修改
- 怎样给微软的Tree控件设置背景?
- 请问高手!弹出一窗口,要返回数组,在父窗口如何得到这个值,字符串可以得到,详见页面
- .net 2005 安装提示 Microsoft Document Explorer 2005 语言包 - 简体中文 错误
- 关于DHTML事件的问题,各位高手帮帮忙
- 一个Castle开源框架问题。大牛进来看看啊。急。
select id ,name ,case pid when 1 then 2 else pid end,
case pid when 1 then (select name from test where id =2) else pname endfrom test
(Select id,name from test where id=2) B Where A.pid=1
update [Test] set PID=(select top 1 ID from Test where ID=2),PName=(select top 1 Name from Test where ID=2) where PID=1
我就不写了。
update A set pid=2 ,pName = B.pName
from test a inner join test b
on b.id = a.pid
where a.pid = 1
所以后面Where A.pid=1的条件要用Where Test.pid=1才行,
但这是例子只有一个条件,而我实际中有很多个条件 每个条件都要加Test. 感觉很不爽 要怎么解决
insert @tabletest values('2','b','','')
insert @tabletest values('3','c','','')
insert @tabletest values('4','d','1','a')
insert @tabletest values('5','e','1','a')
insert @tabletest values('6','f','3','c')update @tabletest set PID= '2' ,[Name]=(select [Name] from @tabletest where [id]='2')
where PID ='1'
select * from @tabletest
from(select [ID] as tempID, [Name] as tempName from @tabletest where [id]='2')B
where PID ='1' 那里面取出来的字段全部用别名就行了
on b.id = a.pid
where a.pid = 1