我想问问,在where语句中,时间类型的字段的匹配问题。比如select * from a where time>'1990-09-23',在oracle,sybase,sqlserver,access,db2中分别该怎么写啊?其中time是日期型的。
还有,在这些数据库中,写SQL语句时,对数值型和字符型数据还有什么不同的要求吗?
...全文
2310打赏收藏
简单问题~请帮忙
我想问问,在where语句中,时间类型的字段的匹配问题。比如select * from a where time>'1990-09-23',在oracle,sybase,sqlserver,access,db2中分别该怎么写啊?其中time是日期型的。 还有,在这些数据库中,写SQL语句时,对数值型和字符型数据还有什么不同的要求吗?
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
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'