create table sal_change (id char(20),item char(20),flowno char(20),check_stauts char(80) )
insert sal_change select  '0001','基本工资','003','4:0001' union all select  '0002','基本工资2','004','4:0001'
create table auduser (flowno char(20),stepno int ,userno char(20))
insert auduser select '003',4,'003003' union all  select '004',4,'003003'其实可以用两个表就可以了
select * from sal_change a
inner join auduser c on a.flowno = c.flowno where c.userno = '003003' and 
exists(charindex(cast(c.stepno as varchar(20))+':',a.check_stauts) > 0)
我自己写的但是那个exists的地方不知道怎样处理

解决方案 »

  1.   

    我写的是这样的select sal_change.* from sal_change a 
    inner join auduser c on a.flowno = c.flowno where c.userno = '003003' and 
    exists(charindex(cast(c.stepno as varchar(20))+':',a.check_stauts) > 0) 但是exists会出错,
    也就是check_stauts中有那个user的步骤号的,用我给的数据应该是 sal_change中的两条数据
      

  2.   

    select * 
    from sal_change a 
    inner join auduser c on a.flowno = c.flowno 
    where c.userno = '003003' 
    and charindex(cast(c.stepno as varchar(20))+':',a.check_stauts) > 0
      

  3.   

    select a.* 
    from sal_change a 
    inner join auduser c on a.flowno = c.flowno and left(a.check_stauts,1)=c.stepno
    where c.userno = '003003' 
    猜楼主的意思。
      

  4.   

    谢谢大家,昨天解决了,去掉exists就行了