您的位置:首页 > 其它

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

2014-07-26 01:38 701 查看
使用字符串拼接函数,创建并解析查询列表条件

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐