积极答复者
XQuery [value()]: 没有函数 '{http://www.w3.org/2001/XMLSchema}:dateTime()'

问题
-
在一个数据库中创建函数,就报错了.
Error 2395, Level 16, State 1, Line 35, Message: XQuery [value()]: There is no function '{http://www.w3.org/2001/XMLSchema}:dateTime()'
函数脚本如下
create FUNCTION [dbo].[FN_EC_ConvertToDateTime]
(
@FullDateTime varchar(50) -- @FullDateTime : yyyy:MM:ddThh:mm:ss timezone
)
RETURNS DateTime
AS
BEGIN
DECLARE @RESULT DATETIME
DECLARE @MSG XML
IF @FullDateTime = '0001-01-01T00:00:00'
RETURN NULL
SET @MSG = @FullDateTime
SET @RESULT = @MSG.value(N'(xs:dateTime((/text())[1]))', 'datetime')
IF @RESULT IS NULL
BEGIN
SET @RESULT = CONVERT(DATETIME, @FullDateTime)
END
ELSE
BEGIN
IF(PATINDEX('%[+]%', @FullDateTime)>0)
BEGIN
SET @RESULT = GetDate()-GetUTCDate() + @RESULT
END
ELSE
BEGIN
RETURN @RESULT
END
END
RETURN @RESULT
END但是在其他数据库服务器上创建的时候 就没这个问题,请问这是什么原因导致的呢?有什么解决办法呢?
If you haven't all the things you want,be grateful for the things you don't have that you didn't want.
- 已编辑 Wison-Ho 2012年4月21日 2:06
答案
-
DB compatibility is set at db level, and can't set system db to lower compatibility level.
- 已建议为答案 Molly Chen_Moderator 2012年4月23日 8:31
- 已标记为答案 Molly Chen_Moderator 2012年4月27日 3:17
全部回复
-
我的实例是sqlserver 2008 版本:10.0.4000
那个数据库是90的兼容级别.
但是我在系统数据库model和90兼容级别的数据库中执行下面的sql都是报错的:
declare @FullDateTime varchar(50)
declare @MSG xml
declare @RESULT DATETIME
select @FullDateTime='2012-04-20T07:22:38.1157068+08:00'
set @MSG=@FullDateTime
SET @RESULT = @MSG.value(N'(xs:dateTime((/text())[1]))', 'datetime')
print @RESULT报错信息都是一样:
Msg 2395, Level 16, State 1, Line 6
XQuery [value()]: 没有函数 '{http://www.w3.org/2001/XMLSchema}:dateTime()'
If you haven't all the things you want,be grateful for the things you don't have that you didn't want.
-
DB compatibility is set at db level, and can't set system db to lower compatibility level.
- 已建议为答案 Molly Chen_Moderator 2012年4月23日 8:31
- 已标记为答案 Molly Chen_Moderator 2012年4月27日 3:17