简单问题~请帮忙

happybeyond 2003-08-07 12:27:35
我想问问,在where语句中,时间类型的字段的匹配问题。比如select * from a where time>'1990-09-23',在oracle,sybase,sqlserver,access,db2中分别该怎么写啊?其中time是日期型的。
还有,在这些数据库中,写SQL语句时,对数值型和字符型数据还有什么不同的要求吗?
...全文
23 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
happybeyond 2003-08-13
  • 打赏
  • 举报
回复
答案都已得到,再次感谢大家的帮助
happybeyond 2003-08-12
  • 打赏
  • 举报
回复
多谢大家鼎立相助,关于sybase 和 db2,有人了解吗?
happybeyond 2003-08-08
  • 打赏
  • 举报
回复
帮帮忙吧,各位
zjcxc 元老 2003-08-08
  • 打赏
  • 举报
回复
对数值型和字符型数据还有什么不同的要求吗?

对数值型没什么要求.

对字符型数据,如果字符常量中的单引号,要用两个单号.
举个例子:

declare @str varchar(10)

--如果要为@str赋值:a'a'b,则要这样写:
set @str='a''a''b'
HawaiiLeo 2003-08-08
  • 打赏
  • 举报
回复
oracle,sqlserver:
日期,字符串都用单引号(双引号)
如:select * from a where date > '1990-09-23'
数字不用引号
如:select * from a where num > 20
access:
日期用#
如:select * from a where date > #1990-09-23#
字符串用单引号
如:select * from a where name = 'leo'
数字不用引号
如:select * from a where num > 20
chao778899 2003-08-08
  • 打赏
  • 举报
回复
oracle:
select * from a where to_char(time,'yyyymmdd')>to_char('1990-09-23','yyyymmdd')
CrazyFor 2003-08-07
  • 打赏
  • 举报
回复
SQL
select * from a where time>'1990-09-23'
这样其实包含1990-09-23的数据,因为SQL是的日期类型还有时间,所以中要是1990-09-23 00:00:01,这时条件就是成立的.
所以改成:select * from a where convert(char(10),time,120)>'1990-09-23'


happybeyond 2003-08-07
  • 打赏
  • 举报
回复
多谢,其他的问题呢?
zjcxc 元老 2003-08-07
  • 打赏
  • 举报
回复
access:
select * from a where time>#1990-09-23#

sqlserver:
select * from a where time>'1990-09-23'
happybeyond 2003-08-07
  • 打赏
  • 举报
回复
多谢

34,575

社区成员

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

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