假设我的邮件地址是[email protected]收到的时候有时候会显示mailzzzlg<[email protected]>,有时候会显示<[email protected]>,
我把来件的邮件地址保存在表A的mail_from字段里,还有一张联系人表B,有联系人邮件字段b.mailadd
保存的时候都是不带符号的:[email protected]
现在想做一个判断,收到邮件时先判断a.mail_from 是否存在与b.mailadd中,如果存在,则…………,不存在则…………请问这两样的字符串怎么判断是否相同

解决方案 »

  1.   

    select * from 表A  a  where exists(select count(1) from 表B  b where a.mail_from=b.mailadd)
      

  2.   

    晕 错了 用case when 判断 case when a.mail_from=b.mailadd then 存在 else 不存在 end 
      

  3.   

    F姐姐,我的意思没表达清楚两个字段的内容[email protected] 和mailzzzlg <[email protected]>,从纯粹的字符串来说是不一样的,从邮件地址来说是一样的,怎么知道他们是一样的
      

  4.   

    能不能用substring 函数截取mailzzzlg <[email protected]>中的[email protected]来与[email protected]判断啊???其实还是不很明白你的意思
      

  5.   

    substring('mailzzzlg <[email protected]>', 10,29)
                                  
    ----------------------------- 
     <[email protected]>(所影响的行数为 1 行)
      

  6.   

    在不知道邮件地址内容的长短、名称的时候咋办?因为这个表里面有很多邮件地址,'mailzzzlg <[email protected]> 这个只是一个例子
      

  7.   

    select substring('mailzzzlg <[email protected]>', charindex('<','mailzzzlg <[email protected]'),len('mailzzzlg <[email protected]'))
                                  
    ----------------------------- 
    <[email protected]>(所影响的行数为 1 行)
    如果是一列 你把'mailzzzlg <[email protected]>'换做列就OK了
      

  8.   

    ----------------------------------------------------------------
    -- Author :fredrickhu(小F 向高手学习)
    -- Date   :2009-06-28 09:53:23
    ----------------------------------------------------------------
    --> 测试数据:[tb]
    if object_id('[tb]') is not null drop table [tb]
    create table [tb]([col] varchar(33))
    insert [tb]
    select 'mailzzzlg<[email protected]>' union all
    select 'abcdefg<[email protected]>' union all
    select 'ddddd<[email protected]>' union all
    select 'dddddddddddddd<[email protected]>'union all
    select 'tttttttttttt<[email protected]>'union all
    select 'sssssssss<[email protected]>'
    --------------开始查询--------------------------
    select substring(col, charindex('<',col),len(col)) from tb----------------结果----------------------------
    /*--------------------------------- 
    <[email protected]>
    <[email protected]>
    <[email protected]>
    <[email protected]>
    <[email protected]>
    <[email protected]>(所影响的行数为 6 行)
    */
      

  9.   

    再把<>给去掉就好了,针对 10 楼的结果。的确 substring 就可以完成。
      

  10.   

    谢谢F姐姐,谢谢各位真心人,本贴已解决,请看下回:http://topic.csdn.net/u/20090628/10/d8e073c1-2145-4560-b18c-fff8ede34157.html