This is really starting to bug me now, if anyone has ever come across it. We don't have a full fledged DBA here and we can't find a setting that would fix the issue.
如果有人遇到它,这真的开始让我感到烦恼。我们在这里没有完整的DBA,我们找不到可以解决问题的设置。
Basically, when running queries, each of us has to set the DATEFORMAT differently. My colleague to the left has to SET DATEFORMAT DMY whereas if I pick up any queries she's written I have to actually force the query into SET DATEFORMAT YMD. My other colleague ends up having to do SET DATEFORMAT YDM like the US format.
基本上,在运行查询时,我们每个人都必须以不同方式设置DATEFORMAT。我左边的同事必须设置DATEFORMAT DMY,而如果我接受任何查询,我必须将查询强制执行SET DATEFORMAT YMD。我的另一位同事最终不得不像美国格式那样进行SET DATEFORMAT YDM。
Is this something that can be changed with a setting somewhere? Of all the workplaces I've used MS SQL Serve I've never come across this before and have no idea how to fix it!
这可以通过某个地方的设置进行更改吗?在我使用MS SQL Serve的所有工作场所中,我以前从未遇到过这种情况,也不知道如何修复它!
EDIT: In response to comments; yes, these queries will be run on the same server and database.
编辑:回应评论;是的,这些查询将在同一服务器和数据库上运行。
1 个解决方案
#1
4
You could define date literals as ISO-8601(culture independent):
您可以将日期文字定义为ISO-8601(独立于文化):
The advantage in using the ISO 8601 format is that it is an international standard. Also, datetime values that are specified by using this format are unambiguous. Also, this format is not affected by the SET DATEFORMAT or SET LANGUAGE settings.
使用ISO 8601格式的优势在于它是一种国际标准。此外,使用此格式指定的日期时间值是明确的。此外,此格式不受SET DATEFORMAT或SET LANGUAGE设置的影响。
SELECT *
FROM tab
WHERE col = 'yyyy-mm-ddThh:mm:ss';
or:
要么:
SELECT *
FROM tab
WHERE col = 'yyyymmdd';
#1
4
You could define date literals as ISO-8601(culture independent):
您可以将日期文字定义为ISO-8601(独立于文化):
The advantage in using the ISO 8601 format is that it is an international standard. Also, datetime values that are specified by using this format are unambiguous. Also, this format is not affected by the SET DATEFORMAT or SET LANGUAGE settings.
使用ISO 8601格式的优势在于它是一种国际标准。此外,使用此格式指定的日期时间值是明确的。此外,此格式不受SET DATEFORMAT或SET LANGUAGE设置的影响。
SELECT *
FROM tab
WHERE col = 'yyyy-mm-ddThh:mm:ss';
or:
要么:
SELECT *
FROM tab
WHERE col = 'yyyymmdd';