Groups | Blog | Home
all groups > sql server programming > may 2007 >

sql server programming : String Manupulation with SQL Help Needed!


vrao5090 NO[at]SPAM sbcglobal.net
5/21/2007 8:22:55 PM
Hello:

Here is the situation:

There is a table (FILELOCATION) with two columns, one has an ID
(integer) and another one is called FILES (string). BTW, these are
not
my creation!

The FILES column contain location of various files. Examples are as
follows:

ID Files
---
------------------------------------------------------------------
1 C:\WINDOWS\Help\AGT0406.HLP
2 C:\WINDOWS\Help\iisHelp\common\400.htm
3 C:\WINDOWS\Help\masked98.chi

and so on.

The requirement is to select files from FileLocation table
and display the data as following columns:

FilesPath Folder Path FileName Prefix Suffix
------------- --------- ------- ------------- --------
--------

Example result of the above columns after running query would be as
follows:

FilesPath
Folder FileName Prefix Sufix
-------------------------------------------------
--------- -------------- --------
-------
C:\WINDOWS\Help\masked98.chi C:\WINDOWS\Help\ masked98.chi masked
98

Essentially, the data shown in Files column of the FileLocation table
has to be parsed and shown in five different results columns. If there
is no
Prefix or Suffix, NULL should be displayed (Example above: "400.htm"
which
has no suffix whereas "masked98" has a suffix of "masked").

Pseudo code may look as follows:

select files as FilesPath, files as xxxx(xxxx,xxxx) Folder,
files as xxxx(xxxx,xxxx) as FileName

and so on.

Will appreciate your quick thoughts. Thanks!

Regards,


Victor
ML
5/22/2007 12:44:01 AM
Here are a few quick thoughts:
- computed columns;
- SUBSTRING, CHARINDEX, REVERSE.

Or:
- SSIS + regular expressions.


Which option would you prefer?


ML

---
Dan Guzman
5/22/2007 7:16:42 AM
If you are using SQL 2005, you have the option of using a CLR function. The
System.IO.Path in .NET contains file parsing methods so you won't need to
re-invent the wheel. In fact, you could even create your own CLR UDT with
the component properties.

--
Hope this helps.

Dan Guzman
SQL Server MVP

[quoted text, click to view]
AddThis Social Bookmark Button