SqlCommand cmd = new SqlCommand("Select id_item,id_noy,txt,date_st,time_st,date_sp,time_sp,ti_cs,cause,ty,cs,cause,tw,id_cu,dep_df FROM dbo.tbl_blue LEFT JOIN dbo.tbl_yellow ON dbo.tbl_blue.id_nob=dbo.tbl_yellow.id_noy WHERE dbo.tbl_blue.archive_date IS NULL AND dbo.tbl_blue.st = 2 AND [color=yellow]dbo.tbl_blue.id_cu = '" + ddlDep.SelectedItem.Value + "' AND dbo.tbl_yellow.date_st BETWEEN '" + ASPxDtst.Date.ToString("yyyy-MM-dd") + "' AND '" + ASPxDtsp.Date.ToString("yyyy-MM-dd") + "' GROUP BY id_item,id_noy,txt,date_st,time_st,date_sp,time_sp,ti_cs,cause,ty,cs,cause,tw,id_cu,dep_df", con);
StringBuilder query = new StringBuilder();
query.Append(" Select id_item,id_noy,txt,date_st,time_st");
query.Append(" ,date_sp,time_sp,ti_cs,cause,ty,cs,cause,tw,id_cu,dep_df ");
query.Append(" FROM dbo.tbl_blue LEFT JOIN dbo.tbl_yellow");
query.Append(" ON dbo.tbl_blue.id_nob=dbo.tbl_yellow.id_noy");
query.Append(" WHERE dbo.tbl_blue.archive_date IS NULL");
query.Append(" AND dbo.tbl_blue.st = 2 ");
//ถ้าเลือกไม่เลือก ALL ให้ค้นหาตาม dbo.tbl_blue.id_cu
if (int.Parse(ddlDep.SelectedItem.Value.Tostring()) != 0)
{
query.Append(" AND dbo.tbl_blue.id_cu = '" + ddlDep.SelectedItem.Value.Tostring() + "'");
}
query.Append(" AND dbo.tbl_yellow.date_st BETWEEN '" + ASPxDtst.Date.ToString("yyyy-MM-dd") +"'");
query.Append(" AND '" + ASPxDtsp.Date.ToString("yyyy-MM-dd") + "' ");
query.Append(" GROUP BY id_item,id_noy,txt,date_st,time_st,date_sp");
query.Append(" ,time_sp,ti_cs,cause,ty,cs,cause,tw,id_cu,dep_df");
SqlCommand cmd = new SqlCommand(query.ToString(), con);
SqlDataReader dr = cmd.ExecuteReader();