比如有两个表,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,怎么写存储过程?

解决方案 »

  1.   

    比如,test1 中的值是 (1,170,'湖北','本科') (2,166,'北京','本科')
    test2中的值是(1,155,165,'湖北,北京,上海','本科,硕士,博士')
    该怎么写?谢谢
      

  2.   

    没太看明白,是在test2中找一条记录,查在test1中与此记录满足条件的记录吗?select * from test1
    where int_a between 155 and 165 and charindex(','+char_b+',',','+'湖北,北京,上海'+',')>0 and charindex(','+char_c+',',','+'本科,硕士,博士'+',')>0