日期:2014-05-18  浏览次数:20363 次

SQL 通配符问题
用VB and sQL server 做系统 下面代码是实现查询功能的 输入职工号和出勤日期,即可查询到该员工本天的出勤时间,精确到秒,出勤时间查询条件那里使用了通配符,但是有问题,请大神帮我改下 
If Len(Text4.Text) > 0 Then
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select * from 员工出勤表 where 职工号='" & Trim(Text4.Text) & "' and 出勤时间 like ' " & Trim(Text5.Text) & " % ' "
Adodc1.Refresh

Else
 MsgBox ("请指定要查找人员的职工号!"), , ("提示")
End If
 PS: 输入 员工号:0001
  输入 出勤日期: 2012/5/7 (出勤日期只是LABEL的caption 值 表中为出勤时间)
  输出结果 员工号:0001 
  出勤时间: 2012/5/7 13:23:23

------解决方案--------------------
试试这个:
VB code

Adodc1.RecordSource = "select * from 员工出勤表 where 职工号='" & Trim(Text4.Text) & "' and datediff(dd,出勤时间, cast('" & Trim(Text5.Text) & "' as datetime))=0 "