View Single Post

   
  #4 (permalink)  
Old 02-28-2008, 07:50 PM
Jerry Boone
 
Posts: n/a
Default Re: Help with UPDATE

No where clause is required unless you want to selectively update certain
data based on column values.

You could do this if you want...

UPDATE mpTable SET myNewColumn = REPLACE(myOriginalColumn, 'A\BO', 'A\C-B0')
Where myOriginalColumn LIKE '%A\BO%'

But if you are making a new column for the modified (replaced) value it will
not show up since the where clause restricts it to only the rows that need
updated. If you are not making a new column, then the where clause would be
great. Another thing... if you want this to run periodically you can setup
a Sql Agent Job to execute this statement as T-SQL and give it a schedule,
or even run when the server is at idle. Of course, the best practice would
be to eliminate the data entry problem when it's entered. But anyway....

--
Jerry Boone
Analytical Technologies, Inc.
http://www.antech.biz


"Jerry Boone" <jerry@antech.biz.nospam> wrote in message
news:ug8ub.4379$zz.1972696130@newssvr30.news.prodi gy.com...
> You could use the REPLACE function.
>
> As a safeguard make a new column on your table and run this statement....
>
> UPDATE mpTable SET myNewColumn = REPLACE(myOriginalColumn, 'A\BO',

'A\C-B0')
>
> If it works good, you may be able to then use "SET myOriginalColumn" and
> remove the new column. May need tweaked, but see what happens?
>
>
>
> --
> Jerry Boone
> Analytical Technologies, Inc.
> http://www.antech.biz
>
>
> "Guinness Mann" <GMann@dublin.com> wrote in message
> news:MPG.1a22a815a633b89898972a@news.newsguy.com.. .
> > I have a column in one of my tables that needs to have about half of its
> > values updated.
> >
> > The data looks like this:
> >
> > A\B0andSomeVaryingStuff.mp3
> >
> > I'd like to update it to:
> >
> > A\C-B0andSomeVaryingStuff.mp3
> >
> > The A, \-sign, B, C, .mp3 and - are literals. The
> > "andSomeVaryingStuff" changes. All I want to do is to replace the \B
> > with \C-B.
> >
> > So I need to say "Find the instances where there is an A\B0 and replace
> > the A\B0 with A\C-B0 leaving the andSomeVaryingStuff.mp3 the same."
> >
> > Note that every row will not need to be updated -- only the ones where
> > the column data begins A\B0.
> >
> > Can you help?
> >
> > Thank you,
> >
> > -- Rick

>
>



Reply With Quote