求一SQL查询语句,在线等

ajianchen2002 2004-09-09 08:34:44
我有一组记录,其中有日期字段,日期的格式为2004-9-9
比如我想查询出2004年9月份的记录
那么SQL语句怎么写呢
我在程序中用LIKE 语句怎么写呢?
StrDate = txtYearPay.Text & "-" & cboMonthPay.Text

Set rsWorking = New ADODB.Recordset
rsWorking.Open "select * from workingtable where 编号='" & cboEmployeeID.Text & " 'and 完成日期 like '" & StrDate% & "'", db, adOpenStatic, adLockOptimistic
运行时提示
类型-声明字符与声明的类型不符

请教高手这个问题怎么解决
非常感谢
...全文
125 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
harryho 2004-09-10
  • 打赏
  • 举报
回复
rsWorking.Open "select * from workingtable where 编号='" & cboEmployeeID.Text & " 'and 完成日期 >=#" & StrDate1 & "# 完成日期<= #" & StrDate2 & "#", db, adOpenStatic,
of123 2004-09-10
  • 打赏
  • 举报
回复
StrDate1 = format(txtYearPay.Text & "-" & cboMonthPay.Text & "-01","yyyy-mm-dd")
StrDate2 = Format(DateAdd("m", 1, strDate1) - 1,"yyyy-mm-dd")
rsWorking.Open "select * from workingtable where 编号='" & cboEmployeeID.Text & " 'and 完成日期 Between #" & StrDate1 & "# And #" & StrDate2 & "#", db, adOpenStatic,
RUKYO 2004-09-10
  • 打赏
  • 举报
回复
StrDate = Format(txtYearPay.Text, "0000") & "-" & Format(cboMonthPay.Text, "00")

Set rsWorking = New ADODB.Recordset
rsWorking.Open "select * from workingtable where 编号='" & cboEmployeeID.Text & " 'and 完成日期 like '%" & StrDate & "%'", db, adOpenStatic, adLockOptimistic
Andy__Huang 2004-09-09
  • 打赏
  • 举报
回复
2004-9-9 的格式與2004-10-9是不一樣的,所以要化所統一格式才好辦。
2004-9-9轉化成2004-09-09,每個日期都是10位婁。

sql="select * from workingtable where 编号='" & cboEmployeeID.Text & " 'and 完成日期 like '" & convert(varchar(7),日期,120) & "%'",

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧