--建立测试表(参数1:操作月份,参数2:操作日期,参数3:数量) DECLARE @t TABLE(stMonth INT,EnterDate DATETIME,EnterQty INT) INSERT INTO @t SELECT 1,'2009-1-10',50 UNION ALL SELECT 1,'2009-1-15',-50 UNION ALL SELECT 2,'2009-2-10',89 UNION ALL SELECT 2,'2009-2-16',80 UNION ALL SELECT 3,'2009-3-10',-50 SELECT * FROM @t WHERE CHARINDEX('2009-02-10',CONVERT(Varchar,EnterDate,120))>0 (5 row(s) affected)stMonth EnterDate EnterQty ----------- ------------------------------------------------------ ----------- 2 2009-02-10 00:00:00.000 89(1 row(s) affected)
where datediff(day,datefield,'2008-12-26')=0 --or where convert(varchar(10),datefield,120)='2008-12-26'
where convert(varchar(10),datefield,120)='2008-12-26' 行不通,好像
SELECT * FROM News where convert(varchar(10),n_time,120)like '%06-30%' 改了下是模糊查询 SELECT * FROM News where convert(varchar(10),n_time,120)='2008-12-26' 也可以查询
--建立测试表(参数1:操作月份,参数2:操作日期,参数3:数量)
DECLARE @t TABLE(stMonth INT,EnterDate DATETIME,EnterQty INT)
INSERT INTO @t
SELECT 1,'2009-1-10',50 UNION ALL
SELECT 1,'2009-1-15',-50 UNION ALL
SELECT 2,'2009-2-10',89 UNION ALL
SELECT 2,'2009-2-16',80 UNION ALL
SELECT 3,'2009-3-10',-50
SELECT * FROM @t WHERE CHARINDEX('2009-02-10',CONVERT(Varchar,EnterDate,120))>0
(5 row(s) affected)stMonth EnterDate EnterQty
----------- ------------------------------------------------------ -----------
2 2009-02-10 00:00:00.000 89(1 row(s) affected)
--or
where convert(varchar(10),datefield,120)='2008-12-26'
行不通,好像
SELECT * FROM News where convert(varchar(10),n_time,120)='2008-12-26' 也可以查询