首页 > 代码库 > 使用字符串拼接函数,创建并解析查询列表条件

使用字符串拼接函数,创建并解析查询列表条件

使用字符串拼接函数,创建并解析查询列表条件

Declare      @store_list varchar(8000)      select  @store_list=,1,3,4,6,8,12,/*   select stuff(@store_list , len(@store_list) , 1 ,‘‘)select @store_list=stuff(@store_list , len(@store_list) , 1 ,‘‘)+‘‘‘‘select @store_list as   store_list_2select @store_list*/
select * From Store s where charindex( , + convert(varchar, s.store_code_id) + ,, @store_list) > 0

 

Declare      @store_list varchar(8000) --select  @store_list=‘1,3,4,6,8,12‘ select * From store s where store_code_id in (1,2,6)  select  @store_list=char(39) select @store_list=@store_list +,+ cast(store_code_id as varchar) From store s where store_code_id in (1,2,6)   select @store_list as store_list_1    --select @store_list=@store_list +‘,‘+   ‘‘‘‘    --select @store_list select sgh.store_grid_id,s.store_code_id,sgh.Description,sgh.username,sgt.grid_type_code,sgt.Description,sg.store_group_description,s.store_code,s.name from store_grid_Header sgh(nolock),Store_Grid_Type sgt (nolock),store_grid_Detail sgd(nolock),store_group sg(nolock),store_group_allocation sga(nolock),store s(nolock)where sgh.grid_type_id=sgt.grid_type_idand sgh.store_grid_id=sgd.store_grid_idand sgd.store_group_id=sg.store_group_idand sg.store_group_id=sga.store_group_idand sga.store_code_id=s.store_code_idand sgt.grid_type_code=pcand s.store_code like %R0115% select @store_list=@store_list  +,+   cast(s.store_code_id  as varchar) from store_grid_Header sgh(nolock),Store_Grid_Type sgt (nolock),store_grid_Detail sgd(nolock),store_group sg(nolock),store_group_allocation sga(nolock),store s(nolock)where sgh.grid_type_id=sgt.grid_type_idand sgh.store_grid_id=sgd.store_grid_idand sgd.store_group_id=sg.store_group_idand sg.store_group_id=sga.store_group_idand sga.store_code_id=s.store_code_idand sgt.grid_type_code=pcand s.store_code like %R0115%select @store_list as store_list_2select @store_list=@store_list +,+  char(39)select @store_list as   store_list_finalselect * From Store s where  charindex( , + convert(varchar, s.store_code_id) + ,, @store_list) > 0