输入的字符串分割后 ,通过查询语句查询结果集

declare @str1 varchar(max), @str2 varchar(max), @str3 varchar(max) 
set @str1 = 'iphone,华为,三星' 
select * into #tbu from [dbo].SplitString(@str1, ',', 1)
create table #uu(FNUMBER varchar(1000), wlmc varchar(1000),fname varchar(1000), FBASEQTY decimal(10,0))
while exists(select 1 from #tbu)
begin
select top 1 @str2=Value from #tbu
insert into #uu 
SELECT m.FNUMBER,ml.fname wlmc,TSL.fname,cast(sum(TI.FBASEQTY) as decimal(10,0)) FBASEQTY
FROM (select FBASEQTY,FSTOCKID,FMATERIALID,FSTOCKSTATUSID from T_STK_INVENTORY where FMATERIALID>1 and FBASEQTY<>0) TI 
inner JOIN (select fnumber,FMASTERID,FMATERIALID from T_BD_MATERIAL where FMASTERID>1) M ON M.FMATERIALID = TI.FMATERIALID 
inner JOIN (select FMATERIALID,FLOCALEID,fname from T_BD_MATERIAL_L where FMATERIALID>1) ML ON (M.FMASTERID = ML.FMATERIALID And ML.FLOCALEID = 2052) 
inner JOIN (select FSTOCKID,fname,FLOCALEID From T_BD_STOCK_L where FSTOCKID>1) TSL ON (TSL.FSTOCKID = TI.FSTOCKID AND TSL.FLOCALEID =2052) where ML.FName like '%'+@str2+'%'
group by ml.fname,m.FNUMBER,tsl.fname,TSL.fname 
order by 1

         delete from #tbu where value=@str2
         end

select distinct * From #uu 
drop table #uu,#tbu












本文转自51GT51CTO博客,原文链接:http://blog.51cto.com/yataigp/2049798 ,如需转载请自行联系原作者


上一篇:《Excel 职场手册:260招菜鸟变达人》一第 22 招 如何输入千分号


下一篇:TensorFlow——CNN卷积神经网络处理Mnist数据集