首页 > 代码库 > 使用字符串拼接函数,创建并解析查询列表条件
使用字符串拼接函数,创建并解析查询列表条件
使用字符串拼接函数,创建并解析查询列表条件
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=‘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_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=‘pc‘and 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。