I have a table that looks like this:
And I need to split the filenames from extensions and put them both into separate columns.
Then I need to roll them all up by directory with another field containing comma separated list of all file extension in that folder.
EG:
Here is what the end product should be:
Here is what I have so far:
select
Length,
(case when Name like '%.%'
then (left((Name), charindex('.', (Name)) - 1))
else ''
end) as FileName
,(case when Name like '%.%'
then reverse(left(reverse(Name), charindex('.', reverse(Name)) - 1))
else ''
end) as Extension
,Directory
FROM dbo.[SourceRetail-V1]
WHERE Mode not like 'd--%'
order by Directory asc
Issues:
- How do I get filenames with something like "FileName.MoreFileName.Txt"
a. It should look like this "FileName.MoreFileName" but my code sees the period and then strips it to "FileName" - How do I roll up by directory yet still keep a running list of all file extension in the directory in another field?
Here is the source in text:
Mode Length Name Directory
-a--- 78497 BSAS.map.xml Y:\Data\Retail\BQ\Maps\SAP
-a--- 4329 T052.tf.sql Y:\Data\Retail\BQ\Maps\SAP
-a--- 24268 T052.map.txt Y:\Data\Retail\BQ\Maps\SAP
-a--- 53837 PAYR.map.xml Y:\Data\Retail\BQ\Maps\SAP
-a--- 4321 LFB1.tf.xml Y:\Data\Retail\BQ\Maps\SAP
-a--- 146089 BSAK.map.xml Y:\Data\Retail\BQ\Maps\SAP
-a--- 4322 LFA1.tf.xml Y:\Data\Retail\BQ\Maps\SAP
-a--- 4325 LFC1.tf.xml Y:\Data\Retail\BQ\Maps\SAP
Intermediary Table:
Mode Length Name Extension Directory
-a--- 78497 BSAS.map xml Y:\Data\Retail\BQ\Maps\SAP
-a--- 4329 T052.tf sql Y:\Data\Retail\BQ\Maps\SAP
-a--- 24268 T052.map txt Y:\Data\Retail\BQ\Maps\SAP
-a--- 53837 PAYR.map xml Y:\Data\Retail\BQ\Maps\SAP
-a--- 4321 LFB1.tf xml Y:\Data\Retail\BQ\Maps\SAP
-a--- 146089 BSAK.map xml Y:\Data\Retail\BQ\Maps\SAP
-a--- 4322 LFA1.tf xml Y:\Data\Retail\BQ\Maps\SAP
-a--- 4325 LFC1.tf xml Y:\Data\Retail\BQ\Maps\SAP
End Product:
Mode Length Directory Extensions
a---- 319998 Y:\Data\Retail\BQ\Maps\SAP xml,sql,txt