码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-07-26 09:50:37      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   使用   io   div   ar   

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

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_2
select @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_id
and sgh.store_grid_id=sgd.store_grid_id
and sgd.store_group_id=sg.store_group_id
and sg.store_group_id=sga.store_group_id
and sga.store_code_id=s.store_code_id
and sgt.grid_type_code=pc
and 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_id
and sgh.store_grid_id=sgd.store_grid_id
and sgd.store_group_id=sg.store_group_id
and sg.store_group_id=sga.store_group_id
and sga.store_code_id=s.store_code_id
and sgt.grid_type_code=pc
and s.store_code like %R0115%

select @store_list as store_list_2


select @store_list=@store_list +,+  char(39)
select @store_list as   store_list_final

select * From Store s where  charindex( , + convert(varchar, s.store_code_id) + ,, @store_list) > 0

 

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

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

标签:des   style   blog   color   使用   io   div   ar   

原文地址:http://www.cnblogs.com/mywiki/p/3869289.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!