根据邮件地址查注册用户使用的名字名;
其中。a 的count是没法确定的所以不知道该怎么用存储过程。
                List<string> selectinfo = new List<string>();
                for (int i = 0; i < a.Count; i++) {
                    string sqlstr = string.Format("select fldloginName as name from tblUser where fldEmail='{0}'",a[i][0]);
                selectInfo.add(sqlstr);
                }问:  现在组织好这么多的sql语句,结果集要返回给跟selectInfo.count一样多行的记录。
查询无此记录的返回null,或者""都行这个sql 该怎么组织,要根据结果如果数据库里没返回结果。就要移除a里面的对应的Index的项,该用啥写。把我给拷到了。忘大虾给出思路。给出代码。给出建议。在此先谢过

解决方案 »

  1.   

    在循环中,将查询语句字串连接合并(每两句间加一个" union all "),循环结束后一次执行查询.
      

  2.   

    在问一下。如果查询出中间的一列没有值,改怎么弄呢
    select fldloginName as name from tblUser where fldEmail='[email protected]' union all select fldloginName as name from tblUser where fldEmail='60483506' union all select fldloginName as name from tblUser where fldEmail='[email protected]'
    name
    admin
    admin结果指出来两个。而中间的那个语句的结果没了。希望
      

  3.   

    前端把各个邮件地址串接起来(以逗号分隔),作为输入参数,调用以下存储过程即可.create proc black2bi(@intput varchar(2000))
    as
    begin
      declare @sql varchar(2000)
      create table #tab (fldEmail varchar(200))
      select @sql='insert into #tab select '''+replace(@intput,',',''' union all select ''')+''' '
      exec(@sql)  select a.fldEmail,b.fldloginName
      from tab a
      left join tblUser b
      on a.fldEmail=b.fldEmail
    end
      

  4.   

    如果查询的结果为null.可不可以让结果为""呢。谢谢
      

  5.   


    create proc black2bi(@intput varchar(2000))
    as
    begin
      declare @sql varchar(2000)
      create table #tab (fldEmail varchar(200))
      select @sql='insert into #tab select '''+replace(@intput,',',''' union all select ''')+''' '
      exec(@sql)  select a.fldEmail,isnull(b.fldloginName,'') fldloginName
      from tab a
      left join tblUser b
      on a.fldEmail=b.fldEmail
    end
      

  6.   


    create proc black2bi(@intput varchar(2000))
    as
    begin
      declare @sql varchar(2000)
      create table #tab (fldEmail varchar(200))
      select @sql='insert into #tab select '''+replace(@intput,',',''' union all select ''')+''' '
      exec(@sql)  select a.fldEmail,isnull(b.fldloginName,'') fldloginName
      from #tab a
      left join tblUser b
      on a.fldEmail=b.fldEmail  drop table #tab
    end