CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  MS-SQL Server >  基础类

数据表里面有DateTime字段, 日期和时间同时进行时间查询应该怎么做?

楼主jhtchina(学习构架设计)2006-03-03 14:57:53 在 MS-SQL Server / 基础类 提问

数据表里面有DateTime字段,   日期和时间同时进行时间查询应该怎么做?  
  有表  
  字段名称                   字段类型  
  GUID                           VARCHAR(50)  
  str_DateTime           DATETIME  
   
  想实现查询2005年5月1日-2006年1月1日  
  时间在18:00到19:00的所有GUID  
  应该怎么做呀?  
  谢谢  
  问题点数:100、回复次数:7Top

1 楼lsqkeke(可可)回复于 2006-03-03 15:03:49 得分 25

select   *   from   tb    
  where   (convert(char(10),str_DateTime,120)   between   '2005-05-01'   and   '2006-01-01')    
  and   (convert(char(5),str_DateTime,108)   between   '18:00'   and   '19:00')Top

2 楼share1011(不知道)回复于 2006-03-03 15:08:16 得分 25

select   GUID   from   表   where   str_DateTime   between   '2005-5-1'and   '2006-1-1'   and   substring(convert(char(19),str_DateTime121),12,5)   between   '18:00'and   '19:00'Top

3 楼share1011(不知道)回复于 2006-03-03 15:13:05 得分 0

select   GUID   from   表   where   (convert(char(10),str_DateTime,121)   between   '2005-5-1'and   '2006-1-1'   and   substring(convert(char(19),str_DateTime121),12,5)   between   '18:00'and   '19:00'  
  Top

4 楼libin_ftsafe(子陌红尘:TS for Banking Card)回复于 2006-03-03 15:14:58 得分 25

select    
          *    
  from    
          表    
  where    
          convert(char(10),str_DateTime,120)   between   '2005-05-01'   and   '2006-01-01'  
          and  
          convert(char(5),str_DateTime,114)   between   '18:00'   and   '19:00'  
  Top

5 楼zhouhaihe()回复于 2006-03-03 15:19:19 得分 25

select   *   from   tb    
  where   (str_DateTime   between   '2005-05-01'   and   '2006-01-01')    
  and   (convert(char(5),str_DateTime,108)   between   '18:00'   and   '19:00')  
  Top

6 楼jhtchina(学习构架设计)回复于 2006-03-03 15:53:14 得分 0

谢谢Top

7 楼geniusli(纠级天使)回复于 2006-03-03 16:24:19 得分 0

select   tablename.*  
  from   tablename  
  where   (convert(char(10),str_DateTime,120)  
  between   '2005-05-01'   and   '2006-01-01')    
  and   (convert(char(5),str_DateTime,108)   between   '18:00'   and   '19:00')Top

相关问题

  • 数据表有个DateTime字段,如何用SQL语句查询前n天,或者前n月、年的数据?
  • 如何在查询分析器里更改某数据表中的字段名?
  • 如何查询一个字段或数据表中是否存在中文?
  • 用sql语句查询数据表中有哪些字段是什么语句?
  • 如何查询出数据表里某个字段的值是相同的数据记录呢?
  • 在.NET 下将一个数据表的某个字段的值做为查询另一张表的WHERE条件.....
  • sap查询数据表中有一包含特殊字符开头的字段 %_cal ,问 SQL语言的写法
  • 在查询数据表后,如何获取该表的字段在数据库中的描述?
  • asp中怎样根据数据表的字段和查询结果生成word和excel
  • 请教!如何对两个相同字段的数据表进行查询显示

关键词

  • 字段
  • 查询
  • datetime
  • convert
  • 时间
  • 应该怎么做
  • guid
  • str
  • where
  • char

得分解答快速导航

  • 帖主:jhtchina
  • lsqkeke
  • share1011
  • libin_ftsafe
  • zhouhaihe

相关链接

  • SQL Server类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo