好吧,有个表 [RenWu] , MSSQL2000
里面这样结构的 (其中 时间和日期是 datetime、id 自动编号、任务 是 nvarchar)
id | 时间 | 日期 | 任务
-------------------------------------------------
1 | 8:12:13 | 2014-6-25 | 要去泡妞
-------------------------------------------------
2 | 9:22:28 | 2014-6-25 | 要去拉屎
====================================
然后,我这样 查不出结果。。。
select * from [RenWu] where 日期='2014-6-25' and 时间>'6:0:0'
表结构是改不了的了,怎么能查到我要 的结果。。
------解决方案--------------------
我这里可以,不过时间那里会变成1900-01-01,而且我是2008的
----------------------------------------------------------------
-- Author :DBA_HuangZJ(发粪涂墙)
-- Date :2014-06-25 14:22:54
-- Version:
-- Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (X64)
-- Jun 17 2011 00:54:03
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据[A]
if object_id('[A]') is not null drop table [A]
go
create table [A]([id] int,[时间] datetime,[日期] datetime,[任务] NVARCHAR(10))
insert [A]
select 1,'8:12:13', '2014-6-25',N'要去泡妞' union all
select 2,'9:22:28', '2014-6-25',N'要去拉屎'
--------------生成数据--------------------------
select * from [A] where 日期='2014-6-25' and 时间>'9:0:0'
----------------结果----------------------------
/*
id 时间 日期 任务
----------- ----------------------- ----------------------- ----------
2 1900-01-01 09:22:28.000 2014-06-25 00:00:00.000 要去拉屎
*/
------解决方案--------------------
select * from RenWu where 日期='2014-06-25' and convert(varchar(100),时间,8)>'06:00:00')>