【问题标题】:Sql query for retrieving member data获取会员数据的sql查询
【发布时间】:2012-03-19 07:39:48
【问题描述】:

我想在 2012 年 5 月 1 日向会员付款,并且我想检索 2011 年 4 月 1 日至 2012 年 3 月 31 日之间的数据。如果我是一张表 (xyz),怎么可能通过查询维护该人成为会员的日期

【问题讨论】:

  • select * from xyz where memberAsOf between '2011-04-01' and '2012-03-31'
  • 这个是 yyyy-mm-dd?
  • 另外:您应该使用正确的 ISO-8601 格式以避免任何与语言和日期格式相关的问题。对于 SQL Server 2005,该格式为 YYYYMMDD(no 破折号!),DATETIME

标签: sql sql-server-2005


【解决方案1】:
select * from xyz where datecoljoined between '2011-04-01' and '2012-03-31'

符合英国设置:

select * from xyz where datecoljoined between '20110401' and '20120331'

【讨论】:

  • 另外:您应该使用正确的 ISO-8601 格式以避免任何与语言和日期格式相关的问题。对于 SQL Server 2005 和 DATETIME,该格式为 YYYYMMDD(no 破折号!)。您带有破折号的格式不安全 - 例如不工作如果你使用SET LANGUAGE British .....(你会得到Msg 242, Level 16, State 3, Line 3 - The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
  • 很高兴知道。更新了答案。
  • 我尝试了以下查询 select memberid,loan_acno,convert(varchar(12), DOS, 105) from mem_loan where DOS between '01-04-2011' 和 '31-01-2012' 但是它仍然向我返回 23-05-2010 的数据有什么错误??
  • 询问 yyyy-mm-dd 但在查询中使用 dd-mm-yyyy 是怎么回事?请改用WHERE DOS BETWEEN '20110401' and '20120331'
  • 是的,但我将数据保存在客户端的 ddmmyyyy 格式的表格中
猜你喜欢
  • 2018-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-07
相关资源
最近更新 更多