SQL Server ISDATE()函数 - 有人可以解释这一点吗? [英] SQL Server ISDATE() Function - Can someone explain this?

查看:536
本文介绍了SQL Server ISDATE()函数 - 有人可以解释这一点吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  

所以我正在查看SQL Server中ISDATE SET DATEFORMAT mdy;
SELECT ISDATE('15 / 04/2008'); - 返回0.
SET DATEFORMAT mdy;
SELECT ISDATE('15 / 2008/04'); - 返回0.
SET DATEFORMAT mdy;
SELECT ISDATE('2008/15/04'); - 返回0.
SET DATEFORMAT mdy;
SELECT ISDATE('2008/04/15'); - 返回1.

最后一个例子返回1(一个有效的日期),但上面的日期格式doesn与函数表达式中的格式不匹配。我认为这是一个文件中的错误,但后来好奇地尝试了它自己,它实际上返回1。



那么为什么'2008/04/15'是有效的日期格式为mdy的日期?



文档在这里: http://msdn.microsoft.com/en-us/library/ms187347(SQL.105).aspx

解决方案

from http://msdn.microsoft.com/en-us/library/ms187347%28SQL.105%29.aspx#SessionSettingDependencies


ISDATE的返回值取决于SET
DATEFORMAT,SET LANGUAGE和默认语言选项设置的设置。


因此,如果给定的字符串不适用于设置的日期格式,它还会使用默认语言选项,该选项允许以格式比如y / m / d

So I was looking at the documentation for the ISDATE() function in SQL Server and saw this in the examples:

SET DATEFORMAT mdy;
SELECT ISDATE('15/04/2008'); --Returns 0.
SET DATEFORMAT mdy;
SELECT ISDATE('15/2008/04'); --Returns 0.
SET DATEFORMAT mdy;
SELECT ISDATE('2008/15/04'); --Returns 0.
SET DATEFORMAT mdy;
SELECT ISDATE('2008/04/15'); --Returns 1.

The last example returns 1 (a valid date) but the date format above doesn't match the format in the expression of the function. I thought it was a mistake in the documentation but then curiously tried it out myself and it does actually return 1.

So why is '2008/04/15' a valid date when the date format is mdy?

Documentation here: http://msdn.microsoft.com/en-us/library/ms187347(SQL.105).aspx

解决方案

from http://msdn.microsoft.com/en-us/library/ms187347%28SQL.105%29.aspx#SessionSettingDependencies

The return value of ISDATE depends on the settings set by SET DATEFORMAT, SET LANGUAGE and default language option.

So if the given string not applies to the set dateformat it also cecks the default language option which allows dates in a format like y/m/d

这篇关于SQL Server ISDATE()函数 - 有人可以解释这一点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆