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.
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 belowsFolderFileC:\Source\DatabaseC:\Source\EmptyContentDocumentLoadContentDocument.batC:\Source\EmptyContentDocumentLoadContentDocument.sqlC:\Source\ExportC:\Source\foldersFiles.txtC:\Source\GetFoldersFiles.batC:\Source\ImportC:\Source\Database\Source.mdfC:\Source\Database\Source_log.ldfC:\Source\Export\ContentDocument.csvi'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))) = 4But 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))) = 4orCHARINDEX('.', sFolderFile)= 0[/CODE] |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-03 : 23:53:38
|
[code]SELECT sFolderFileFROM TableWHERE sFolderFile LIKE '%.%'AND CHARINDEX('.',STUFF(sFolderFile,1,CHARINDEX('.',sFolderFile),''))=0[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
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 @tblTempFolderFilewhere charindex('.', dbo.fnParseString(1, '\', reverse(sFolderFile))) = 0[/code] |
 |
|
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 @tblTempFolderFilewhere charindex('.', dbo.fnParseString(1, '\', reverse(sFolderFile))) = 0
see below for getting definition of fnParseString UDFhttp://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|
|
|