select a.userid, a.type, a.chkdate,DATEADD(yyyy,b.chkperiod,a.chkdate) as mustcheckdate
from customer a inner join type b on a.type=b.type where ( DATEADD(yyyy,b.chkperiod,a.chkdate) < ? )
select a.userid, a.type, a.chkdate,DATEADD(yyyy,b.chkperiod,a.chkdate) from customer a inner join type b on a.type=b.type where ( DATEADD(yyyy,b.chkperiod,a.chkdate) < ? )
谢谢楼上的各位,我是在vb数据设计器中写出下列语句
select a.userid, a.type, a.chkdate,DATEADD(yyyy,b.chkperiod,a.chkdate) from customer a inner join type b on a.type=b.type where ( DATEADD(yyyy,b.chkperiod,a.chkdate) < ? )
但是在vb数据设计器中,始终报出如下错误:
[ODBC :Microsoft Access]参数不正确,需求2。
SELECT userID 用户ID,Type 设备,Chkdate 检验日期,待检日期=DATEADD(yy,B.chkperiod,chkdate)
FROM 用户表 A
INNER JOIN (
SELECT * FROM 类型表 WHERE Chkperiod IS NOT NULL
) B
ON A.type=B.typename
WHERE DATEADD(yy,B.chkperiod,chkdate) <= '2006-7-24'
if exists(select * from sysobjects where name='用户表' and xtype='U') drop table 用户表
if exists(select * from sysobjects where name='类型表' and xtype='U') drop table 类型表
GO
--生成测试用数据,为SELECT初始环境
CREATE TABLE 用户表(UserId Varchar(10),Type varchar(10),Chkdate datetime)
INSERT INTO 用户表 SELECT '001','T1','2006-7-7'
UNION ALL SELECT '002','T2','2005-6-5'
UNION ALL SELECT '003','T1','2004-2-25'
CREATE TABLE 类型表(Typename varchar(10),Chkperiod int)
INSERT INTO 类型表 SELECT 'T1',2
UNION ALL SELECT 'T2',3
select * from 用户表
select * from 类型表
GO
--此处为用来查询的SELECT语句
SELECT userID 用户ID,Type 设备,Chkdate 检验日期,待检日期=DATEADD(yy,B.chkperiod,chkdate)
FROM 用户表 A INNER JOIN 类型表 B ON A.type=B.typename
WHERE DATEADD(yy,B.chkperiod,chkdate) <= '2006-7-24'