1.两个不同数据库对应字段相应操作
//操作
模版:insert into data2.table2(字段1,字段2,字段) select 字段j,字段k,字段m from data1.table1
举例:insert into Hospitals.dbo.Deparments(DepartmentName) select distinct(Departments)from NanFan.dbo.UserInfo where Unit=‘南方医院‘
//更新
update Hospitals.dbo.UserInfo set Hospitals.dbo.UserInfo.Departments=‘97195203-b6af-4246-a578-69741e512af3‘
where Hospitals.dbo.UserInfo.UserName in(select NickName from NanFan.dbo.UserInfo where Unit=‘南方医院‘ and Departments=‘关节与骨病外科‘)
2.拼接某个字段内的所有值
select stuff((select ‘-‘+NickName from UserInfo for xml path (‘‘)),1,1,‘‘)
原文地址:http://www.cnblogs.com/115FXC/p/3864636.html