27,579
社区成员
发帖
与我相关
我的任务
分享
-- 动态SQL 可以考虑一下
create table x(C_id varchar(60) )
go
create table y(C_id varchar(60) )
go
insert into x
select number from master..spt_values where type ='p' and number between 1 and 5
go
insert into y
select number from master..spt_values where type ='p' and number between 11 and 15
go
select * from x
select * from y
go
declare @sql varchar(max) = ''
select @sql= @sql +' union all select c_id from ' + object_name(id)
from syscolumns where name ='C_id'
select @sql = substring(@sql,11,len(@sql))
exec ( @sql )
go
drop table x , y
go
(5 行受影响)
(5 行受影响)
C_id
------------------------------------------------------------
1
2
3
4
5
(5 行受影响)
C_id
------------------------------------------------------------
11
12
13
14
15
(5 行受影响)
c_id
------------------------------------------------------------
1
2
3
4
5
11
12
13
14
15
(10 行受影响)
bcp "SELECT * FROM 表名 WHERE C_id = 1234" queryout 表名.txt -c -T