SQL Server adding the slashes to the date on the fly(SQL Server 动态添加斜线到日期)
问题描述
我想弄清楚如何为我的数据添加某种掩码.目前我有这样的查询:
I am trying to figure out how to add some sort of mask to my data. Currently I have a query like this:
SELECT [EmployeeTC_No] AS "Employee TC#"
,[pye_nlast] AS "Name Last"
,[pye_nfirst] AS "Name First"
,[Dept] AS "Department"
,[pye_status] AS "Active"
,[HireDate] AS "Hire Date"
,[SeparationDate] AS "Separation Date"
FROM [testing].[dbo].[testing]
hiredate 和 separatordate 列中的数据显示为 09282015,但我需要日期来显示斜杠(/"),如 09/28/2015 有没有办法为这些动态添加某种掩码?
The data in the hiredate and separationdate column shows as 09282015 but I need the dates to show the slash ("/") like 09/28/2015 is there any way to add some kind of mask on the fly for these?
推荐答案
这并不理想,因为您似乎没有将日期存储为日期类型.如果它们是 varchars,并且您只想添加斜杠以进行演示,则可以在需要的地方插入它们.这是假设你总是有一个 8 个字符的日期:
This is not ideal, since you appear to not be storing dates as a date type. If they are varchars, and you want to just add slashes for presentation, you can insert them where needed. This is assuming you always have a 8char date:
SELECT STUFF(STUFF(your_col, 3, 0, '/'), 6, 0, '/')
这篇关于SQL Server 动态添加斜线到日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQL Server 动态添加斜线到日期
基础教程推荐
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 在多列上分布任意行 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
