where cMATypeCode = '商品通知单' AND bValid = 1 这个是我从数据库取数据的条件,大家无视
--例,此处的@t2相当于你的cdcust_bank declare @t1 table(id1 int,id2 int); declare @t2 table(id2 int,name varchar(20)); insert into @t1 select 1,1 union select 2,2 insert into @t2 select 1,'name1' union select 1,'name2'; select t1.id1,isnull((select top 1 name from @t2 t2 where t2.id2=t1.id2),'') name from @t1 t1;
这个是我从数据库取数据的条件,大家无视
--例,此处的@t2相当于你的cdcust_bank
declare @t1 table(id1 int,id2 int);
declare @t2 table(id2 int,name varchar(20));
insert into @t1 select 1,1 union select 2,2
insert into @t2 select 1,'name1' union select 1,'name2';
select t1.id1,isnull((select top 1 name from @t2 t2 where t2.id2=t1.id2),'') name from @t1 t1;