先谢谢这里的高手了 . . 原查询语句:
select * BMID,BMMC,BMB from table1 where BMID<>0 order by BMPX
现在将table2 的字段BMGR合并到BMMC中显示 .. 比如
table1 table2
BMMC BMGR
1 1
1 3
2 3 查询后为:
BMID BMMC BMB
* 1 *
* 1 *
* 2 *
* 1 *
* 3 *
* 3 *
select * BMID,BMMC,BMB from table1 where BMID<>0 order by BMPX
现在将table2 的字段BMGR合并到BMMC中显示 .. 比如
table1 table2
BMMC BMGR
1 1
1 3
2 3 查询后为:
BMID BMMC BMB
* 1 *
* 1 *
* 2 *
* 1 *
* 3 *
* 3 *
insert into @tb select '1','1'
insert into @tb select '1','3'
insert into @tb select '2','3'select bmid='*',BMMC as bmmc,bmb='*' from @tb
union all
select bmid='*',BMGR as bmmc,bmb='*' from @tbbmid bmmc bmb
* 1 *
* 1 *
* 2 *
* 1 *
* 3 *
* 3 *
有的话简单的union all 即可
insert into @a select '1'
insert into @a select '1'
insert into @a select '2'declare @b table (BMGR varchar(20))
insert into @b select '1'
insert into @b select '3'
insert into @b select '3'select bmid='*',BMMC as bmmc,bmb='*' from @a
union all
select bmid='*',BMGR as bmmc,bmb='*' from @bbmid bmmc bmb
* 1 *
* 1 *
* 2 *
* 1 *
* 3 *
* 3 *
?
union all
select bmcr from tb2
union all
select bmid = '*' , bmcr , bmb = '*' from tb2