ASP.NET如何做两个数据库表的对比
ASP.NET如何做同一数据库中两个结构相同数据库表的数据对比
最好能有这样的显示:
A B
| A | | B |
| 中 | | 中 |
| B | | A |
| 没 | | 没 |
| 有 | | 有 |
| 的 | | 的 |
做到一目了然的对比效果,请求高手指教
[解决办法]
Create Table #A( id int identity(1,1), AName nvarchar(50), BName nvarchar(50))Create Table #B( id int identity(1,1), AName nvarchar(50), BName nvarchar(50))insert into #Aselect 'A1','A1' union select 'A2','A2' union select 'A3','A3' union select 'A4','A4' union select 'A5','A5' union select 'A6','A6' union select 'A7','A7' insert into #Bselect 'A1','A1' union select 'A2','A2' union select 'A3','A3' union select 'A4','A4' union select 'A5','A5' union select 'A8','A8' union select 'A9','A9' SELECT c.*,case isnull(a.id,'') When '' Then '无' ELSE '有' END A,case isnull(b.id,'') When '' Then '无' ELSE '有' END BFROM (Select * from #Aunion SELECT * FROM #B) cLEFT JOIN #A a ON a.AName=c.AName AND a.BName=c.BNameLEFT JOIN #B b ON b.AName=c.AName AND b.BName=c.BNameDROP TABLE #ADROP TABLE #B1 A1 A1 有 有2 A2 A2 有 有3 A3 A3 有 有4 A4 A4 有 有5 A5 A5 有 有6 A6 A6 有 无6 A8 A8 无 有7 A7 A7 有 无7 A9 A9 无 有