您的位置:程序门 -> vb -> 数据库(包含打印,安装,报表)



access里如何用一条sql语句得到生提醒的功能,急!!!


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


access里如何用一条sql语句得到生提醒的功能,急!!!
发表于:2008-01-18 09:57:02 楼主
set   rs.open   "select   *   from   customer   where   datediff('d',date(),#(cstr(year(date()))   +   '-   '+format(birthday,'mm-dd')))#   <="&daynum&"   order   by   jifen   desc",conn,1,1

我用这条语句提示错误,不知是什么原因.~~~

microsoft   vbscript   编译器错误   (0x800a03f3)
缺少   '='
发表于:2008-01-18 10:08:221楼 得分:0
改成
rs.open   "select   *   from   customer   where   datediff('d',date(),datevalue(cstr(year(date()))   +   '-   '+format(birthday,'mm-dd')))   <="&daynum&"   order   by   jifen   desc",conn,1,1

还是不行:(     提示"标准表达式中数据类型不匹配。"
有人知道是什么问题吗?
发表于:2008-01-18 10:16:222楼 得分:0
字符串拼接问题,用debug.print打印,看下对不对
发表于:2008-01-18 10:33:303楼 得分:0
什么使用debug.print,我是在asp里调用的,不知道什么操作,你能帮我看一下吗?
发表于:2008-01-18 10:36:184楼 得分:0
response.write   "select       *       from       customer       where       datediff('d',date(),datevalue(cstr(year(date()))       +       '-       '+format(birthday,'mm-dd')))       <="&daynum&"       order       by       jifen       desc"

然后把写出来的语句拿到sql里去执行一下,或者贴到这里给大家看看也行:)
发表于:2008-01-18 10:47:025楼 得分:0
response   只是把这条语句输出,daynum=7,没有问题,输出的是

select   *   from   customer   where   datediff('d',date(),format(birthday,'yyyy-mm-dd'))   <=7   order   by   jifen   desc

问题好像是出在format这个上面,提示:标准表达式中数据类型不匹配
我直接在access   里执行,也是出现这个问题
发表于:2008-01-18 11:04:296楼 得分:0
在sql里有format函数吗????????
发表于:2008-01-18 11:07:057楼 得分:0
不过也不用管有没有format函数,因为datediff这个函数是比较两个日期的,但format得到的应该是字符串吧,直接写成
datediff('d',date(),birthday) <=7不行吗?
发表于:2008-01-18 11:10:278楼 得分:0
select       *       from       customer       where       datediff('d',date(),format(birthday,'yyyy-mm-dd'))       <=7       order       by       jifen       desc  

这个应该是没问题的吧?


但是下面这个拼接的语句
select               *               from               customer               where               datediff('d',date(),datevalue(cstr(year(date()))               +               '-               '+format(birthday,'mm-dd')))               <="&daynum&"               order               by               jifen               desc

注意   年和   月日   中间的那个横线,后面多了好几个空格,会不会是这个问题
发表于:2008-01-18 11:10:299楼 得分:0
select       *       from       customer       where       datediff('d',date(),format(birthday,'yyyy-mm-dd'))       <=7       order       by       jifen       desc  

这个应该是没问题的吧?


但是下面这个拼接的语句
select               *               from               customer               where               datediff('d',date(),datevalue(cstr(year(date()))               +               '-               '+format(birthday,'mm-dd')))               <="&daynum&"               order               by               jifen               desc

注意   年和   月日   中间的那个横线,后面多了好几个空格,会不会是这个问题
发表于:2008-01-18 11:13:1510楼 得分:0

select               *               from               customer               where               datediff('d',date(),datevalue(cstr(year(date()))               +               '-               '+format(birthday,'mm-dd')))               <="&daynum&"               order               by               jifen               desc

注意   年和   月日   中间的那个横线,后面多了好几个空格,会不会是这个问题
你把空格杀了看看
发表于:2008-01-18 11:13:4011楼 得分:0
我晕,怎么发了这么多。。
发表于:2008-01-18 12:36:0312楼 得分:0
先问一下你用的是什么数据库
如果是sql数据库,应该是没有"date()"函数的,只有"getdate()"函数
发表于:2008-01-18 12:57:3713楼 得分:0
我用的是access+asp,format函数我是想取出生日的月和日,加上当前的年,得到一个日期,跟当前的日期比效,

空格去掉了,也是不行,:(

rs.open   "select   *   from   customer   where   datediff('d',date(),datevalue(cstr(year(date()))+'-'+format(birthday,'mm-dd')))   <=7   order   by   jifen   desc",conn,1,1
发表于:2008-01-18 14:25:4014楼 得分:0
你想要的效果,是不是想找出数据库中所有在7天内生日的人???

你试试这样:
vbscript code
dim sql sql = "select * from [customer] where birthday - date() <= 7 order by jifen desc" rs.open sql, conn, 1


上面的字符,我在sql中测试通过了(我在sql中测试的时候,用的不是date()函数,而是getdate()函数,不过既然你说access只支持date()函数,所以我就改成date()了)
但我这里没有安装access,所以不能测试


其实最主要的,还是要看你数据库中birthday字段的类型是否为日期类型,如果是的话,数据库在分析sql语句的时候会自动运算的。
发表于:2008-01-18 14:29:2615楼 得分:0
噢,错了错了!!!!
我上面的sql语句不管用,我一时没想到年份的问题。。。。。。。。
发表于:2008-01-18 14:39:5316楼 得分:0
我这里没有access,所以无法更详细的测试
但我换了个角度,试试看不理数据库中的日期,而是用今天的日期:
vbscript code
dim birthday, sql birthday = monthdate()) & "-" if len(birthday) = 2 then birthday = "0" & birthday if lendaydate()) = 1 then birthday = birthday & "0" & daydate()) else birthday = birthday & daydate()) end if sql = "select * from [customer] where birthday like '%" & birthday & "' order by jifen desc" rs.open sql, conn, 1
发表于:2008-01-18 14:41:1017楼 得分:0
哎,我又忘记了lz要的是7天内生日的人。。。。。。。。。。
我上面的只是得出当天生日的人。。。。。。。。。
发表于:2008-01-18 16:57:3418楼 得分:0
是的,这个只能得到当天生日的人,如果是指定多少天的要考虑月份和年份的问题,:(


快速检索

最新资讯
热门点击