SQL SERVER 2012新增函数之字符串函数FORMAT详解
16lz
2022-01-06
前言
本文主要介绍的是使用 FORMAT函数将日期/时间和数字值格式化为识别区域设置的字符串。下面话不多说,来看详细的介绍吧。
格式如下:
format(value,format,culture)
FORMAT 依赖于 .NET Framework公共语言运行时 (CLR) 的存在。
declare @date datetime = '2014-01-01' select FORMAT( @date, 'd', 'en-US' ) as 'US English Result' ,FORMAT( @date, 'd', 'en-gb' ) as 'Great Britain English Result' ,FORMAT( @date, 'd', 'de-de' ) as 'German Result' ,FORMAT( @date, 'd', 'zh-cn' ) as 'Simplified Chinese (PRC) Result'; select FORMAT( @date, 'D', 'en-US' ) as 'US English Result' ,FORMAT( @date, 'D', 'en-gb' ) as 'Great Britain English Result' ,FORMAT( @date, 'D', 'de-de' ) as 'German Result' ,FORMAT( @date, 'D', 'zh-cn' ) as 'Chinese (Simplified PRC) Result'; /* USEnglish Result Great BritainEnglish Result German Result Simplified Chinese (PRC) Result ------------------------------------------------------------- ------------------------------------------------------------ 1/1/2014 01/01/2014 01.01.2014 2014/1/1 USEnglish Result Great BritainEnglish Result German Result Chinese (Simplified PRC) Result ------------------------------------------------------------- ------------------------------------------------------------ Wednesday,January 01, 2014 01 January 2014 Mittwoch, 1. Januar 2014 2014年1月1日 */
如果说我想要得到'2014年01月01日的结果,怎么得到呢?
select FORMAT( @date, 'yyyy年MM月dd日', 'zh-cn') as 当前日期 /* 当前日期 -------------------- 2014年01月01日 */
if object_id('[tb]') is not null drop table [tb] create table [tb]([id] int,[NumericValue] numeric(3,2)) insert [tb] select 1,1.26 union all select 2,2.78 union all select 3,9.83 select *, FORMAT([NumericValue], 'G', 'en-us') as 'General Format', FORMAT([NumericValue], 'C', 'en-us') as 'Currency Format', FORMAT([NumericValue], 'G', 'de-de') as 'General Format', FORMAT([NumericValue], 'C', 'de-de') as 'Currency Format' from [tb] /* id NumericValue General Format Currency Format General Format Currency Format ------------------- ---------------- ----------------- ----------------------------------------- 1 1.26 1.26 $1.26 1,26 1,26 € 2 2.78 2.78 $2.78 2,78 2,78 € 3 9.83 9.83 $9.83 9,83 9,83 € */
总结
更多相关文章
- SQL Server之JSON 函数详解
- ES6 变量声明,箭头函数,数组方法,解构赋值,JSON,类与继承,模块化练习
- 箭头函数的基础使用
- Python技巧匿名函数、回调函数和高阶函数
- 浅析android通过jni控制service服务程序的简易流程
- Android(安卓)bluetooth介绍(四): a2dp connect流程分析
- Android架构分析之使用自定义硬件抽象层(HAL)模块
- Android中OpenMax的适配层
- android 包管理系统分析