DECLARE @Date DATE
DECLARE @FileName VARCHAR(1000)
DECLARE @FilePath VARCHAR(8000)
SET @FilePath = 'S:\FFgh\ENG\dataload'
SELECT @FileName = REVERSE(SUBSTRING(REVERSE(REPLACE@FilePath,'.DAT','')),1,CHARINDEX '\',REVERSE(REPLACE(@FilePath,'.DAT','')))-1))
SELECT @Date = CAST(Date AS DATE) FROM FileHeader Where FinalName = @FileName
SELECT CAST(@Date AS DATETIME) AS Date, @@ROWCOUNT AS HeaderFooter
这是我的代码,如果我使用文件名而不是@FileName它是有效的,否则会给我错误。
答案 0 :(得分:0)
REPLACE
和CHARINDEX
找不到一些括号。在下面添加..
DECLARE @Date DATE
DECLARE @FileName VARCHAR(1000)
DECLARE @FilePath VARCHAR(8000)
SET @FilePath = 'S:\FFgh\ENG\dataload'
SELECT @FileName = REVERSE(SUBSTRING(REVERSE(REPLACE(@FilePath,'.DAT','')),1,CHARINDEX ('\',REVERSE(REPLACE(@FilePath,'.DAT','')))-1))
SELECT @Date = CAST(Date AS DATE) FROM FileHeader Where FinalName = @FileName
SELECT CAST(@Date AS DATETIME) AS Date, @@ROWCOUNT AS HeaderFooter