需求是这样滴:一个表codeTable就一个字段code(类似流水号)BH0001
BH0003
BH0005查询之后,希望得到这样的结果:表resultBH0002
BH0004只要找出断号,其它没要求。应该可以用SQL语句解决这个问题吧?

解决方案 »

  1.   

    在生成是就连续
    存储过程中游标遍历
    或循环,截取数字,判断是否连续list.Contains判断
      

  2.   

    string[] arr = { "BH0001", "BH0003", "BH0005" };
                 var result = (from s in arr select Regex.Match(s, @"\d+").Value.TrimStart('0')).ToArray();
                 foreach (string s in result)
                 {
                     Console.WriteLine(s);
                 }
    1
    3
    5
    循环判断
      

  3.   

    string[] arr = { "BH0001", "BH0003", "BH0005" };
    string[] arr = { "BH0001", "BH0003", "BH0006" };var result = (from s in arr select Regex.Match(s, @"\d+").Value.TrimStart('0')).ToArray();
    foreach (string s in result)
    {
    Console.WriteLine……
      

  4.   

    with codes as(select 'BH0001' as code union all select 'BH0002' union all select 'BH0003' union all 
    select 'BH0004' union all select 'BH0005') 
    select code from codes where not exists(select 1 from codeTable where codeTable.code=codes.code);就是生成全部的信息有点困难。
      

  5.   

    看来还是截取字符串比较速度。            string s1 = "BH001";
                string s2 = "BH010";            int change = 3; //字符串变化的位数            string s3 = s1.Substring(0, s1.Length - change); //截取字母部分            Console.WriteLine(s1);            //循环次数
                int count = (int.Parse(s2.Substring(s2.Length - change)))
                    - (int.Parse(s1.Substring(s1.Length - change)));            for (int i = 0; i < count; i++)
                {
                    int temp = int.Parse(s1.Substring(s1.Length - change)) + 1;  //变成整数并加一
                    s1 = s3 + temp.ToString().PadLeft(change, '0');  //生成新字符串
                    Console.WriteLine(s1);
                }
     
                Console.ReadLine();