SELECT SR.id, SR.relationshipList, SR.fromDateTime, SR.toDateTime, SR.scheduleCls, 
      SR.scheduleClsAim, SR.scheduleClsAimDesc, SR.scheduleClsAimResult, 
      SR.scheduleClsAimResultDesc, SR.contactRe, SR.inputDate, SR.spend, 
      RB.oLastName, RB.oFirstName, RB.lastName, RB.firstName
FROM ScheduleRecord SR CROSS JOIN
      RelationshipBasic RB
WHERE (RB.id IN (REPLACE(SR.relationshipList, ',', [',']))) AND 
      (SR.userId = ' ST_0000001 ')  ORDER BY SR.inputDate我想用 REPLACE 函数 替换 relationshipList 字段里面的 , 为 ','  这样 如何写转义符啊啊。

解决方案 »

  1.   

    REPLACE 函数 替换 relationshipList 字段里面的 , 为 ','replace(relationshipList,',',N'','')
      

  2.   

    SELECT SR.id, SR.relationshipList, SR.fromDateTime, SR.toDateTime, SR.scheduleCls, 
          SR.scheduleClsAim, SR.scheduleClsAimDesc, SR.scheduleClsAimResult, 
          SR.scheduleClsAimResultDesc, SR.contactRe, SR.inputDate, SR.spend, 
          RB.oLastName, RB.oFirstName, RB.lastName, RB.firstName 
    FROM ScheduleRecord SR CROSS JOIN 
          RelationshipBasic RB 
    WHERE (RB.id IN (REPLACE(SR.relationshipList, ',', ''','''))) AND 
          (SR.userId = ' ST_0000001 ')  ORDER BY SR.inputDate 
      

  3.   

    The replace function requires 3 arguments.提示这样的
      

  4.   

    select replace('中华,全国,总工,会',N',',N''',''') --字符串中出现的字符边界符用“两个单个号”
    /*
    (无列名)
    中华','全国','总工','会
    */
      

  5.   


    select replace('a,b',',',''',''')                                                                                                                                                                                                                                                                 
    --------------------
    a','b(所影响的行数为 1 行)
      

  6.   

    虽然执行成功了 但是没有出现效果
    现在需求是这样的
    有一个表是记录人物的表  人物ID 为A B C 
    现在他在另外一个表中的班级表中  一个事件选择了 三个人物 A B C
    数据表为
    班级表 
    id renwu 
    1  A,B,C人物表
    id 
    A
    B
    C
    我现在 搜索 A 人物所在的班级
    我的思路是  
    select * from  人物表 , 班级表 where  人物表 in (班级ID)
    所以可以通过 replace 函数 替换掉 A B C 中间的 , 为 'A','B','C' 就可以用 in 函数了 
    对吗?
      

  7.   


    select replace('中华,全国,总工,会',N',',N''',''') --字符串中出现的字符边界符用“两个单个号”
    如何
    select 中华 in replace('中华,全国,总工,会',N',',N''',''')
     
      

  8.   


    select a.id from 班级表 a,人物表 b
    where charindex(','+b.id+',',','+renwu+',')>0
      

  9.   


    declare @tA table(id int,renwu varchar(10))
    insert @tA select 
    1,  'A,B,C' union all select
    2,  'D,B,C' union all select
    3,  'F,B,C' union all select
    4,  'A,B,C' declare @tB table(id  varchar(10))
    insert @tB select
    'A' union all select  
    'B'  union all select
    'C' select a.id from @TA a,@TB b
    where charindex(','+b.id+',',','+renwu+',')>0
    AND B.ID='A'id
    -----------
    1
    4(2 行受影响)