FORMAT 函数在 sql server 2008 R2 中不起作用 [英] FORMAT function not working in sql server 2008 R2
本文介绍了FORMAT 函数在 sql server 2008 R2 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
DECLARE @d DATETIME = '01/01/2011';
SELECT FORMAT ( @d, 'd', 'en-US' ) AS US_Result;
我在 SQL Server 2008 R2 中使用上述代码,但遇到错误:
I am using above code in SQL Server 2008 R2 but it is encountering an error:
'FORMAT' 不是可识别的内置函数名称.
'FORMAT' is not a recognized built-in function name.
如何使用FORMAT
函数?
推荐答案
FORMAT 函数从 2012 版本开始可用.在早期版本中,使用这个:
FORMAT function is available from version 2012 onwards. In earlier versions, use this:
DECLARE @d DATETIME = '01/01/2011';
SELECT replace(replace(' '+convert(varchar(10),@d,101),' 0',''),'/0','/')
然而,格式化是前端应用程序的工作.
However, formatting is the job of the front end application.
这篇关于FORMAT 函数在 sql server 2008 R2 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文