我正在尝试在 SQL Server 2008 R2 中创建视图。我需要输入当前日期作为导入完成的日期。这是我所拥有的:
SET NOCOUNT ON;
declare @SQL as varchar(4000)
--@CD as date
--set @CD = convert(varchar(30), cast(getdate() as date), 110)
-- Insert statements for procedure here
set @SQL = 'CREATE VIEW vw_GCS_Export
As
select division, [primary image id],[Item Number], [Brand Name],[Marketing Description],
[Colours]as Colors,[Live Date],[Sample Type],substring([FileName],charindex('+ CHAR(39) + '_' + CHAR(39) +',[FileName],1)+1,CHARINDEX('+ CHAR(39) + '.' + CHAR(39) +',[FileName],1)-5) as BatchID,
'+ CHAR(39) + '670' + CHAR(39) +' as Status, [Primary image ID] + '+ CHAR(39) + '_P' + CHAR(39) +' as [Shot Name],
Cast(Null as varchar(50))as [Swatch/Variation],Cast(Null as varchar(50))as [Alternate Shot],[UserName],' + CAST(convert(date,Sysdatetime(),110)as varchar(10)) + ' as [Import Date],
Cast(Null as varchar(50))as [Return Instructions],Cast(Null as varchar(50))as [Rush Request]
from Sheet1$'
EXEC (@SQL)
select * from vw_GCS_Export
当我得到结果时,字段 ImportDate 返回为 2008。我希望 04/01/2013 或类似的时间。我只需要将当前日期插入该字段。
我尝试了几种强制转换和转换组合,甚至尝试了一个返回当前日期和时间但没有运气的函数。