我有下面的脚本,结果 YYYYMMDD.但是,我需要 MMDDYYYY 格式的结果.
I have the below script which results YYYYMMDD. However, I need the result in MMDDYYYY format.
有人可以帮忙吗?我不希望数字之间有破折号/笔划/句点.
Can someone please assist? I want no dash/stroke/periods between the numbers.
SELECT CONVERT(VARCHAR(10), RowUpdateDateTime, 112)
from MyTable
结果:20141113
我希望它看起来像 11132014.
我尝试了 FORMAT 语法,但它需要很长时间才能运行.
I tried the FORMAT syntax but it was taking forever to run.
查看 CONVERT() 文档:没有一种格式与您正在寻找的完全匹配.看起来 110 是最接近的.我们可以通过添加一个 REPLACE() 调用来完成:
Take a look at the CONVERT() documentation: none of formats match exactly what you're looking for. It looks like 110 is the closest. We can finish by adding a REPLACE() call:
SELECT REPLACE(CONVERT(VARCHAR(10), RowUpdateDateTime, 110),'-','') from MyTable
我也想知道你为什么要这样做.大多数情况下,您的客户端代码可以更有效地处理此类转换.
I also wonder why you're doing this at all. Much of the time, a conversion like this can be handled more effectively by your client code.
这篇关于有效地以 MMDDYYYY 格式输出日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
将每个子标记转换为具有多个分隔符的单列-SQLConverting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(将每个子标记转换为具有多个分隔符的单列-SQ
如何从多个表创建视图?How can I create a view from more than one table?(如何从多个表创建视图?)
根据前一行内的计算值创建计算值Create calculated value based on calculated value inside previous row(根据前一行内的计算值创建计算值)
如何将表格的前两列堆叠成一列,但也仅将第三How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何将表格的前两列堆
递归 t-sql 查询Recursive t-sql query(递归 t-sql 查询)
将月份名称转换为日期/月份编号(问题和答案的组Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(将月份名称转换为日期/月份编号(问题和答案的组合