Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Find and Replace using SQL

 
   Database Help (Home) -> MSEQ RSS
Next:  Choose Replication Method  
Author Message
HWhite

External


Since: Jan 16, 2009
Posts: 2



(Msg. 1) Posted: Fri Jan 16, 2009 4:10 pm
Post subject: Find and Replace using SQL
Archived from groups: microsoft>public>sqlserver>mseq (more info?)

I posted this in the Access forum too, but I think this may be a better
place...
=======================================

I have an access field that was a hyperlink, now converted to text. It is
messy. Here's an example of what it looks like after converted to text.

020411-1568-07-25-08-Depo
Docs#E-File%20Indices/1568/Depo.%20Docs%20from%20S.Haney%20file/020411-1568-07-25-08-Depo%20Docs.PDF#

I need to do the following and I think a SQL statement is what I need but
don't know enough to do it without help.

I need to find and delete anything that exists before /1568
I need to find and rename /1568 to 1568
I need to find and rename / to \
I need to find and rename %20 to a space
I need to find and rename 1568\ to t:\
I need to find and delete #

The end result should look like this

t:\1568\Depo. Docs from S.Haney file\020411-1568-07-25-08-Depo Docs.PDF

I then need to convert it back to a hyperlink.

Thank you for your help.

 >> Stay informed about: Find and Replace using SQL 
Back to top
Login to vote
Hugo Kornelis

External


Since: Jan 11, 2008
Posts: 440



(Msg. 2) Posted: Sat Jan 17, 2009 4:25 pm
Post subject: Re: Find and Replace using SQL [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Fri, 16 Jan 2009 16:10:01 -0800, HWhite wrote:

>I posted this in the Access forum too, but I think this may be a better
>place...

Hi HWhite,

That depends. If you need a solution in Access, the Access forum is a
better place. This is a SQL Server group, so you'll get a SQL Server
solution here.

(snip)
>I need to find and rename 1568\ to t:\
(snip)
>The end result should look like this
>
>t:\1568\Depo. Docs from S.Haney file\020411-1568-07-25-08-Depo Docs.PDF

This doesn't match the above part of the spec. I'll give you two
solutions, one that matches the spec and one that matches the sample
output.

CREATE TABLE Test (TheText varchar(200));
go
INSERT INTO Test(TheText)
VALUES ('020411-1568-07-25-08-Depo
Docs#E-File%20Indices/1568/Depo.%20Docs%20from%20S.Haney%20file/020411-1568-07-25-08-Depo%20Docs.PDF#');
go
UPDATE Test
SET TheText = REPLACE(REPLACE(REPLACE(STUFF(TheText, 1,
PATINDEX('%1568/%', TheText) + 4, 't:\1568\'), '/', '\'), '%20', ' '),
'#', '');
--SET TheText = REPLACE(REPLACE(REPLACE(STUFF(TheText, 1,
PATINDEX('%1568/%', TheText) + 4, 't:\'), '/', '\'), '%20', ' '), '#',
'');
SELECT * FROM Test;
go
DROP TABLE Test;
go

>I then need to convert it back to a hyperlink.

That is a client-side function. SQL Server doesn't know of any
hyperlinks.

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis

 >> Stay informed about: Find and Replace using SQL 
Back to top
Login to vote
HWhite

External


Since: Jan 16, 2009
Posts: 2



(Msg. 3) Posted: Sat Jan 17, 2009 4:25 pm
Post subject: Re: Find and Replace using SQL [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

thanks for your help... and yes, you were correct... the final result needed
to be simply t:\ instead of t:\1568

"Hugo Kornelis" wrote:

> On Fri, 16 Jan 2009 16:10:01 -0800, HWhite wrote:
>
> >I posted this in the Access forum too, but I think this may be a better
> >place...
>
> Hi HWhite,
>
> That depends. If you need a solution in Access, the Access forum is a
> better place. This is a SQL Server group, so you'll get a SQL Server
> solution here.
>
> (snip)
> >I need to find and rename 1568\ to t:\
> (snip)
> >The end result should look like this
> >
> >t:\1568\Depo. Docs from S.Haney file\020411-1568-07-25-08-Depo Docs.PDF
>
> This doesn't match the above part of the spec. I'll give you two
> solutions, one that matches the spec and one that matches the sample
> output.
>
> CREATE TABLE Test (TheText varchar(200));
> go
> INSERT INTO Test(TheText)
> VALUES ('020411-1568-07-25-08-Depo
> Docs#E-File%20Indices/1568/Depo.%20Docs%20from%20S.Haney%20file/020411-1568-07-25-08-Depo%20Docs.PDF#');
> go
> UPDATE Test
> SET TheText = REPLACE(REPLACE(REPLACE(STUFF(TheText, 1,
> PATINDEX('%1568/%', TheText) + 4, 't:\1568\'), '/', '\'), '%20', ' '),
> '#', '');
> --SET TheText = REPLACE(REPLACE(REPLACE(STUFF(TheText, 1,
> PATINDEX('%1568/%', TheText) + 4, 't:\'), '/', '\'), '%20', ' '), '#',
> '');
> SELECT * FROM Test;
> go
> DROP TABLE Test;
> go
>
> >I then need to convert it back to a hyperlink.
>
> That is a client-side function. SQL Server doesn't know of any
> hyperlinks.
>
> --
> Hugo Kornelis, SQL Server MVP
> My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
>
 >> Stay informed about: Find and Replace using SQL 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
index on a view - Hello, I have a table (TAB) and A View with alias (VIEW) Table cod varchar 3 descr carchar 60 my view cod alias COd1 descr alias DES Now i need a index on view with key COD1 I can't create it. Can..

Creating an alias - I have an alias that can get very long because it maintains a information of where it came from. Is there a way to alias an alias? My first thought was: Declare @T1 varchar(128) Set T1 = 'MyAlias' .... Inner Join Table1 as @T1 This of course does no...

Formatting numeric fields in select-clause - This is propably a very simple question, but I can“t seem to find the answer to it in the documentation. I want to format a numeric field so the result is right justified and zero-filled. ex select 1 will give the result 01 How do I manage this..

Simple Query problem - Sample table as follows Order ID Stock Code Status --------- ------- ------- 203 STK1 3 203 STK2 2 203 STK4 3 204 STK1 3 204 STK5 3 205 ..

query assistance -return most recent date - I have a table that has two fields, pkg_num, which is a number, and del_date_time, which is a date-time. The table can contain duplicate pkg_num values, as long as the del_date_time values are different for any given number. I need a query that will...
   Database Help (Home) -> MSEQ All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]