日期:2014-05-18 浏览次数:20611 次
declare @T table(c1 varchar(1),c2 int)
insert @T
select 'a',10 union all
select 'b',90 union all
select 'c',102 union all
select 'd',121 union all
select 'e',111
declare @s_SchoolProvinceID varchar(10)
set @s_SchoolProvinceID='b,c,e'
select * from @T where charindex(','+c1+',',','+@s_SchoolProvinceID+',')>0
/*
---- -----------
b    90
c    102
e    111
*/
--mysql 中貌似有个函数INSTR 可以代替sql server 中的charindex
------解决方案--------------------
drop table if exists t_tdscore;
drop PROCEDURE  if exists SelectScore;
create table t_tdscore 
(
id varchar(10),
name varchar(10),
value INT
);
insert into t_tdscore values('430000','1',1);
insert into t_tdscore values('110000','2',2);
insert into t_tdscore values('120000','3',3);
insert into t_tdscore values('230000','4',4);
DELIMITER $$
CREATE PROCEDURE SelectScore(
  s_SchoolProvinceID varchar(200)
)
begin
select * from t_tdscore where FIND_IN_SET(id,s_SchoolProvinceID);
END$$
 
DELIMITER ;
call SelectScore('430000,110000,120000');
/*
430000    1    1
110000    2    2
120000    3    3
*/