Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Data extraction from file and Folder path

Author  Topic 

lemondash
Posting Yak Master

159 Posts

Posted - 2013-06-03 : 10:08:36
Hello All,

I'ver got a csv file that gets bulked inputted on a daily basis. An example of the data is like the below

sFolderFile
C:\Source\Database
C:\Source\EmptyContentDocumentLoadContentDocument.bat
C:\Source\EmptyContentDocumentLoadContentDocument.sql
C:\Source\Export
C:\Source\foldersFiles.txt
C:\Source\GetFoldersFiles.bat
C:\Source\Import
C:\Source\Database\Source.mdf
C:\Source\Database\Source_log.ldf
C:\Source\Export\ContentDocument.csv

i'm running the below query to return row's that have a file extension.

select
sFolderFile as [FullPath],
SUBSTRING(sFolderFile, CHARINDEX('.', sFolderFile) + 1, len(sFolderFile)) as [FileExtension],
reverse(left(reverse(sFolderFile),charindex('\',reverse(sFolderFile),1)-1)) as [FullFileName]
from tblTempFolderFile
where
len(SUBSTRING(sFolderFile, CHARINDEX('.', sFolderFile) + 1, len(sFolderFile))) = 3
or
len(SUBSTRING(sFolderFile, CHARINDEX('.', sFolderFile) + 1, len(sFolderFile))) = 4

But i'm stuck trying to get the file name without the file extension.

Any help would be great ?

MuMu88
Aged Yak Warrior

549 Posts

Posted - 2013-06-03 : 11:36:12
[CODE]

select
sFolderFile as [FullPath],
(CASE WHEN CHARINDEX('.', sFolderFile)= 0 THEN 'NULL'
ELSE SUBSTRING(sFolderFile, CHARINDEX('.', sFolderFile) + 1, len(sFolderFile)) END) as [FileExtension],
reverse(left(reverse(sFolderFile),charindex('\',reverse(sFolderFile),1)-1)) as [FullFileName]
from @TEMP
where
len(SUBSTRING(sFolderFile, CHARINDEX('.', sFolderFile) + 1, len(sFolderFile))) = 3
or
len(SUBSTRING(sFolderFile, CHARINDEX('.', sFolderFile) + 1, len(sFolderFile))) = 4
or
CHARINDEX('.', sFolderFile)= 0
[/CODE]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-03 : 23:53:38
[code]
SELECT sFolderFile
FROM Table
WHERE sFolderFile LIKE '%.%'
AND CHARINDEX('.',STUFF(sFolderFile,1,CHARINDEX('.',sFolderFile),''))=0
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

waterduck
Aged Yak Warrior

982 Posts

Posted - 2013-06-04 : 00:16:08
[code]declare @tblTempFolderFile table(sFolderFile varchar(200))
insert into @tblTempFolderFile select
'C:\Source\Database' union all select
'C:\Source\EmptyContentDocumentLoadContentDocument.bat' union all select
'C:\Source\EmptyContentDocumentLoadContentDocument.sql' union all select
'C:\Source\Export' union all select
'C:\Source\foldersFiles.txt' union all select
'C:\Source\GetFoldersFiles.bat' union all select
'C:\Source\Import' union all select
'C:\Source\Database\Source.mdf' union all select
'C:\Source\Database\Source_log.ldf' union all select
'C:\Source\Export\ContentDocument.csv' union all select
'C:\Source\Export\ContentDocument.haha'

select *
from @tblTempFolderFile
where charindex('.', dbo.fnParseString(1, '\', reverse(sFolderFile))) = 0[/code]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-04 : 00:33:54
quote:
Originally posted by waterduck

declare @tblTempFolderFile  table(sFolderFile varchar(200))
insert into @tblTempFolderFile select
'C:\Source\Database' union all select
'C:\Source\EmptyContentDocumentLoadContentDocument.bat' union all select
'C:\Source\EmptyContentDocumentLoadContentDocument.sql' union all select
'C:\Source\Export' union all select
'C:\Source\foldersFiles.txt' union all select
'C:\Source\GetFoldersFiles.bat' union all select
'C:\Source\Import' union all select
'C:\Source\Database\Source.mdf' union all select
'C:\Source\Database\Source_log.ldf' union all select
'C:\Source\Export\ContentDocument.csv' union all select
'C:\Source\Export\ContentDocument.haha'

select *
from @tblTempFolderFile
where charindex('.', dbo.fnParseString(1, '\', reverse(sFolderFile))) = 0



see below for getting definition of fnParseString UDF
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -