1、sqlsever 连表update修改字段
update tableA set ttt= a.ttt from tableA a, tableB b where b.bs=a.id and a.ss='0'
2、排除两个表的差异数据
select * from B where (select count(1) from A where A.ID = B.ID) = 0
3、查询插入
insert A (.......) select ...... from B where .....
4、递归
--查询父级和子级插入到临时表,然后再查询临时表(记得用后把临时表删除)
WITH TEMP
AS (SELECT Id,
Code,
Name,
ParentId
FROM [dbo].[AspSysDepartments]
WHERE Id = 38 --查询父级
UNION ALL
SELECT B.Id, --查询子级
B.Code,
B.Name,
B.ParentId
FROM TEMP A
INNER JOIN [dbo].[AspSysDepartments] B
ON B.ParentId = A.Id)
SELECT Id,
Code,
Name,
ParentId
FROM TEMP --获取递归后的集合