如何找出某时间段的全部记录

vaccum 2002-12-25 08:23:44
表内出生年月日字段为日期型(如1979-10-02 00:00:00.000)。

假设,客户端查询文本框内有一日期型变量Birth(录入格式为YYYY.MM),假如客户输入1979.10,我想用SQL选择出所有1979.10出生的人,此语句该如何写?要求:WHERE子句运算符左侧不允许用函数!
LIKE行吗?

...全文
47 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
vaccum 2002-12-26
  • 打赏
  • 举报
回复
感谢各位,不过除了hbwhwanghua(mikel),各位好象没注意我帖子中的要求,
select * from tablename where Birth >='1979-10-01' and birth < '1979-11-01'
为说明问题,暂把1979-10-01叫第1变量,1979-11-01叫第2变量。
回到应用程序开发环境中,不知各位用什么,就那DELPHI为例,我的思路是把EDIT1.TEXT的月份取出来(想让它是日期型,只有年月,让用户输入,不知是否可行?),再+1,但如果客户输入的是1979.12,第2变量会是1980-01吗?
我的思路可行吗?
cm8983 2002-12-26
  • 打赏
  • 举报
回复
select * from tablename where convert(char(7),yourdate,102)=convert(char(7),Birth,102)
AMDfuns 2002-12-25
  • 打赏
  • 举报
回复
select * from tablename t1
where birth =
(select t2.birth from tablename t2
where t1.birth = t2.birth
and convert(varchar,t2.birth,111) like '%'+'1978/10'+'%'
)

试试看一定好用。

pengdali 2002-12-25
  • 打赏
  • 举报
回复
select * from tablename where year(Birth)=@年 and month(Birth)=@月
hbwhwanghua 2002-12-25
  • 打赏
  • 举报
回复
select * from tablename where Birth >='1979-10-01' and birth < '1979-11-01'

34,872

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧