select * from table where datediff(year,birth,getdate())>=0 and datediff(year,birth,getdate())<=11用正则把 sql 的0 和 11分别出去来,怎么写 
先谢谢啦

解决方案 »

  1.   

    using System;
    using System.Text.RegularExpressions;class A 

      static void Main()
      {
        string s = "select * from table where datediff(year,birth,getdate())>=0 and datediff(year,birth,getdate())<=11";
        foreach (Match m in Regex.Matches(s, @"\d+"))
        {
          Console.WriteLine(m.Value);
        }
      }
    }
    /* 程序输出:
    0
    11
    */
      

  2.   

    不是这个意思
    例如 
    select * from table where datediff(year,birth,getdate())>=0 and datediff(year,birth,getdate())<=11 and id>8要取出
    datediff(year,birth,getdate())最小值 (就是取0)  还有最大值(就是11)
    用正则怎么取
      

  3.   

    using System;
    using System.Text.RegularExpressions;class A 

      static void Main()
      {
        string s = "select * from table where datediff(year,birth,getdate())>=0 and datediff(year,birth,getdate())<=11 and id>8";
        string p = @"(?i)datediff\(year,birth,getdate\(\)\)>=(?<min>\d+).*?datediff\(year,birth,getdate\(\)\)<=(?<max>\d+)";
        Match  m = Regex.Match(s, p);
        Console.WriteLine("min: {0}  max: {1}", m.Groups["min"], m.Groups["max"]);
      }
    }
    /* 程序输出:
    min: 0  max: 11
    */