1个回答
2015-03-19
展开全部
CREATE TABLE A(a1 INT,a2 INT ,a3 INT ,a10 INT )
CREATE TABLE b (a2 INT ,a3 INT,a10 INT ,a9 INT ,a5 INT )
DECLARE @s NVARCHAR(4000)
SET @s = ''
SELECT @s = @s + ',' + 'isnull('+QUOTENAME(name)+','''')'
FROM syscolumns
WHERE id = OBJECT_ID('A')
AND name IN ( SELECT NAME FROM sys.columns WHERE object_id=OBJECT_ID('A')
INTERSECT
SELECT NAME FROM sys.columns WHERE object_id=OBJECT_ID('B') )
SET @s = STUFF(@s, 1, 1, '')
EXEC ('select '+@s+' from A ')
CREATE TABLE b (a2 INT ,a3 INT,a10 INT ,a9 INT ,a5 INT )
DECLARE @s NVARCHAR(4000)
SET @s = ''
SELECT @s = @s + ',' + 'isnull('+QUOTENAME(name)+','''')'
FROM syscolumns
WHERE id = OBJECT_ID('A')
AND name IN ( SELECT NAME FROM sys.columns WHERE object_id=OBJECT_ID('A')
INTERSECT
SELECT NAME FROM sys.columns WHERE object_id=OBJECT_ID('B') )
SET @s = STUFF(@s, 1, 1, '')
EXEC ('select '+@s+' from A ')
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询