我有这个查询,它提取了很久以前在数据库中编程的日期数值,并将其显示为 19930215.202300000。因此,对于三个不同的列,我到目前为止所做的是将字符串转换为日期和时间
现有查询:
select SerialNum as [Serial Number],ts_sitename As Site,(case m.Scratched
when 0 then 'Live'
when 1 then 'Free'
END) as Status, Note as Comment, (case Destroyed when 0 then 'NO'
when 1 then 'YES' END) as [Destroyed],
SUBSTRING(cast(EffectiveDate as char), 1, 8) AS [Effective Date Added],
SUBSTRING(cast(EffectiveDate as char), 10, 6) AS [Effective Time Added],
SUBSTRING(cast(ScratchedDate as char), 1, 8) AS [Scratched Date],
SUBSTRING(cast(ScratchedDate as char), 10, 6) AS [Scratched Time],
SUBSTRING(cast(ChangedPurgeDate as char), 1, 8) AS [Purge Date],
SUBSTRING(cast(ChangedPurgeDate as char), 10, 6) AS [Purge Time],
(select fl_filename from TheFiles_tab where mg_filenum = fl_filenum) as [Dataset],
(select hs_hostname from TheHosts_tab where mg_hostnum = hs_hostnum) as [Host],
(select UserCode from [User] where mg_usernum = UserId) as [UserCode]
from ((Media m left join MediaGenT g on m.MediaId = g.mg_medianum)
join TheSites_tab s on m.SiteId = s.ts_sitenum)
join Note n on m.NoteId = n.NoteId;
所以这显示有效日期为 20120327
但是所需的输出是2012-03-27
当前显示有效时间为213100
所需输出为 21:31:00
.. 其他四个日期和时间列也是如此。
请注意,我使用 SQL Server 2008 来运行我的查询。
任何人都可以对我的代码进行任何编辑以获得所需的输出,我只是不擅长字符串操作吗?我很想立即对其进行测试。