问题描述
我想弄清楚如何为我的数据添加某种掩码.目前我有这样的查询:
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 动态添加斜线到日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!