DECLARE
@Filename varchar(100)
,@FilenameSmall varchar(100)
,@BatchNameType varchar(50)
@Filename varchar(100)
,@FilenameSmall varchar(100)
,@BatchNameType varchar(50)
SET @BatchNameType = SPACE(0)
SET @Filename = '05 May 2017_FP.xlsx'
SET @Filename = '05 May 2017_FW.xlsx'
SET @Filename = '05 May 2017_HA.xlsx'
SET @Filename = '05 May 2017_WHO.xlsx'
SET @Filename = 'GENERICS-20170531_152713.xlsx'
SET @Filename = '05 May 2017_FP.xlsx'
SET @Filename = '05 May 2017_FW.xlsx'
SET @Filename = '05 May 2017_HA.xlsx'
SET @Filename = '05 May 2017_WHO.xlsx'
SET @Filename = 'GENERICS-20170531_152713.xlsx'
SET @FilenameSmall = LOWER(@Filename)
SET @BatchNameType += CASE WHEN PATINDEX('%_fw.xlsx', @FilenameSmall) > 0 THEN 'FINALWAY-' ELSE SPACE(0) END
SET @BatchNameType += CASE WHEN PATINDEX('%_fp.xlsx', @FilenameSmall) > 0 THEN 'FINALWAY-' ELSE SPACE(0) END
SET @BatchNameType += CASE WHEN PATINDEX('%_ha.xlsx', @FilenameSmall) > 0 THEN 'HOMEALONE-' ELSE SPACE(0) END
SET @BatchNameType += CASE WHEN PATINDEX('%_who.xlsx', @FilenameSmall) > 0 THEN 'WHO-' ELSE SPACE(0) END
SET @BatchNameType += CASE WHEN PATINDEX('%_fp.xlsx', @FilenameSmall) > 0 THEN 'FINALWAY-' ELSE SPACE(0) END
SET @BatchNameType += CASE WHEN PATINDEX('%_ha.xlsx', @FilenameSmall) > 0 THEN 'HOMEALONE-' ELSE SPACE(0) END
SET @BatchNameType += CASE WHEN PATINDEX('%_who.xlsx', @FilenameSmall) > 0 THEN 'WHO-' ELSE SPACE(0) END
IF( LEN(@BatchNameType) > 0)
BEGIN
SELECT [@Filename] = @Filename, [@FilenameSmall] = @FilenameSmall,
[BatchName] = @BatchNameType + SUBSTRING(@FilenameSmall,8,4) +
CASE SUBSTRING(@FilenameSmall,4,3)
WHEN 'jan' THEN '01'
WHEN 'feb' THEN '02'
WHEN 'mar' THEN '03'
WHEN 'apr' THEN '04'
WHEN 'may' THEN '05'
WHEN 'jun' THEN '06'
WHEN 'jul' THEN '07'
WHEN 'aug' THEN '08'
WHEN 'sep' THEN '09'
WHEN 'oct' THEN '10'
WHEN 'nov' THEN '11'
WHEN 'dec' THEN '12' end
+ SUBSTRING(@FilenameSmall,1,2)
END
ELSE
BEGIN
SELECT [@Filename] = @Filename, [@FilenameSmall] = @FilenameSmall,
[BatchName] = LEFT(@Filename, PATINDEX('%.xlsx', @FilenameSmall) - 1)
END
[BatchName] = @BatchNameType + SUBSTRING(@FilenameSmall,8,4) +
CASE SUBSTRING(@FilenameSmall,4,3)
WHEN 'jan' THEN '01'
WHEN 'feb' THEN '02'
WHEN 'mar' THEN '03'
WHEN 'apr' THEN '04'
WHEN 'may' THEN '05'
WHEN 'jun' THEN '06'
WHEN 'jul' THEN '07'
WHEN 'aug' THEN '08'
WHEN 'sep' THEN '09'
WHEN 'oct' THEN '10'
WHEN 'nov' THEN '11'
WHEN 'dec' THEN '12' end
+ SUBSTRING(@FilenameSmall,1,2)
END
ELSE
BEGIN
SELECT [@Filename] = @Filename, [@FilenameSmall] = @FilenameSmall,
[BatchName] = LEFT(@Filename, PATINDEX('%.xlsx', @FilenameSmall) - 1)
END
Comments
Post a Comment