比如有两个表,test1表示自身条件的表,存放很多人的自身条件
test2表示自身要求对象的条件的表
create table test1
(
id int not null primary key,
int_a int, /* 身高 */
char_b varchar(100),
char_c varchar(100)
)create table test2
(
id int not null primary key,
int_a1 int, /* 对方最低的身高 */
int_a2 int, /* 对方最高的身高 */
char_b varchar(100),
char_c varchar(100)
)
test1.char_b 表示所在地,如 '湖北'
test2.char_b 表示要求对方的所在地,如'北京,湖北,上海',条件之间以逗号分割
现在我要根据我要求对方的条件(存放在test2中)来从test1中查找满足我的要求的id,怎么写存储过程?
test2表示自身要求对象的条件的表
create table test1
(
id int not null primary key,
int_a int, /* 身高 */
char_b varchar(100),
char_c varchar(100)
)create table test2
(
id int not null primary key,
int_a1 int, /* 对方最低的身高 */
int_a2 int, /* 对方最高的身高 */
char_b varchar(100),
char_c varchar(100)
)
test1.char_b 表示所在地,如 '湖北'
test2.char_b 表示要求对方的所在地,如'北京,湖北,上海',条件之间以逗号分割
现在我要根据我要求对方的条件(存放在test2中)来从test1中查找满足我的要求的id,怎么写存储过程?
test2中的值是(1,155,165,'湖北,北京,上海','本科,硕士,博士')
该怎么写?谢谢
where int_a between 155 and 165 and charindex(','+char_b+',',','+'湖北,北京,上海'+',')>0 and charindex(','+char_c+',',','+'本科,硕士,博士'+',')>0