Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
根据SQL查询向dropdownlist添加值_Sql_Asp.net_Sql Server 2005_Drop Down Menu - Fatal编程技术网

根据SQL查询向dropdownlist添加值

根据SQL查询向dropdownlist添加值,sql,asp.net,sql-server-2005,drop-down-menu,Sql,Asp.net,Sql Server 2005,Drop Down Menu,我有一个dropdownlist,它的值由一个 select emp_card_no, emp_name + '-' + cast(emp_card_no as varchar) + '(' + datename(MM,a.dt_of_leave) + ' - ' + cast(year(a.dt_of_leav

我有一个
dropdownlist
,它的值由一个

select emp_card_no, 
       emp_name + '-' 
                + cast(emp_card_no as varchar) 
                + '(' 
                + datename(MM,a.dt_of_leave) 
                + ' - ' 
                + cast(year(a.dt_of_leave)as varchar)
                +')' emp_name 
from emp_mst a 
where month(a.dt_of_leave) >= month(getdate())-1  
  and year(a.dt_of_leave) = 
        case when month(getdate())=1 then year(getdate())-1 
             else year(getdate()) 
        end
order by emp_name 
其结果与此类似

[![SQL输出][1][1]

现在,我想要的是,在
Emp_name
列中,我想在
(2016年4月)
之后添加文本作为
过程
待定

select emp_mkey, * from emp_mon_day
where emp_mkey = 312
 and month = 4
 and year = 2016
若查询返回任何结果,则
处理
否则
挂起

注意

第一个查询列
Emp\u卡号
Emp\u mon\u day
表中的
Emp\u mkey

另请参见绑定dropdownlist的代码

protected void funfillEmployee()
{
    DataTable DtCombo = new DataTable();
    string strdate = System.DateTime.Now.ToString("dd/MM/yyyy");

    DtCombo = ObjPriDal.ExecuteDataTable("select emp_card_no, emp_name + '-' + cast(emp_card_no as varchar)+ '(' + datename(MM,a.dt_of_leave)  + ' - ' + cast(year(a.dt_of_leave)as varchar)+')' emp_name  " +
                         "  from emp_mst a where month(a.dt_of_leave) >= month(getdate())-1  and  year(a.dt_of_leave)= case " +
                         "   when  month(getdate())=1 then year(getdate())-1 else year(getdate()) end order by emp_name ");

    cmbEmp_Name.DataTextField = "emp_name";
    cmbEmp_Name.DataValueField = "emp_card_no";
    cmbEmp_Name.DataSource = DtCombo;
    cmbEmp_Name.DataBind();
    cmbEmp_Name.Items.Insert(0, new ListItem("--Select--", "0"));
    DtCombo.Clear();
}
让我知道怎么做


我正在使用
SQL-server-2005

尝试以下方法:

select a.emp_card_no, 
       a.emp_name + '-' 
                  + cast(a.emp_card_no as varchar) 
                  + '(' 
                  + datename(MM,a.dt_of_leave) 
                  + ' - ' 
                  + cast(year(a.dt_of_leave)as varchar)
                  +') '
                  +                
                    case when m.emp_mkey IS NULL 
                         then 'PENDING' 
                         else 'PROCESS' 
                    end                  
                  emp_name 
from emp_mst a 
LEFT JOIN emp_mon_day m ON m.Emp_mkey = a.Emp_card_no 
                        AND m.month = month(a.dt_of_leave) 
                        AND  m.year = year(a.dt_of_leave)
where month(a.dt_of_leave) >= month(getdate())-1  
  and year(a.dt_of_leave) = 
        case when month(getdate())=1 then year(getdate())-1 
             else year(getdate()) 
        end
order by emp_name 
但你可能已经修改了那部分

AND m.month = month(a.dt_of_leave) AND  m.year = year(a.dt_of_leave)

由于月份和年份是保留字,我怀疑您是否这样命名了列,但您没有指定其他名称

@coder啊,是的,您显然没有告诉我们这两个表之间存在1对多的关系。我以为是1比1。按照顺序,你可以在你的
Emp\u mon\u day
表中有重复的
Emp\u mkey
,对吗?@coder ok然后是2个解决方案,因为它仍然太模糊,无法给你一个完美的答案:1。如果您可以匹配两个表中的日期(年+月),则将其添加到
ON
子句中:
LEFT JOIN emp\u mon\u day m ON m.emp\u mkey=a.emp\u卡号和m.month=month(a.dtu of_休假)和m.year=year(a.dtu of_休假)
2.否则,我将向您推荐另一种方法,在您的
选择中,
不存在
。。。试试1。给我反馈如果你想从myside澄清你的疑问,如果你需要表格的脚本和任何其他东西来尝试,请告诉我。我会给你。因为我还没有明白你的观点,我必须要做的是??问题是:你想从
emp\u mon\u day
表中检查同一
emp\u卡号和同一年/月是否存在记录,还是只想检查同一
emp\u卡号是否存在记录?如果1将
左连接
与我之前评论中的一个相适应,如果2我将向您提供另一个查询,我想在
emp\u mon\u day
的基础上检查同一年/月的
流程
挂起
逻辑将起作用。如果还有其他疑问,请告诉我