Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Query?

LEGEND ,
Jun 23, 2008 Jun 23, 2008

Copy link to clipboard

Copied

update TableName set ColumnName=replace(ColumnName,'if matches 555',
'replace with 666')

Above works for items that I have a specific description I want to replace.

What if I just want to update all the items in a certain column? How do
I do that. In other words, I want to everything in ColumnName to be 777

Something like this?

update TableName set ColumnName=replace(ColumnName,'%%', 'replace with 777')

Would this do it?
TOPICS
Server side applications

Views

305
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 23, 2008 Jun 23, 2008

Copy link to clipboard

Copied

Art wrote:
>
> update TableName set ColumnName=replace(ColumnName,'%%', 'replace with
> 777')
>
> Would this do it?

I tried this on a dead table and it didn't do anything.

What could be used as a wild card for %%?

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 23, 2008 Jun 23, 2008

Copy link to clipboard

Copied

Art wrote:
> update TableName set ColumnName=replace(ColumnName,'if matches 555',
> 'replace with 666')
>
> Above works for items that I have a specific description I want to replace.
>
> What if I just want to update all the items in a certain column? How do
> I do that. In other words, I want to everything in ColumnName to be 777
>
> Something like this?
>
> update TableName set ColumnName=replace(ColumnName,'%%', 'replace with
> 777')
>
> Would this do it?

You want to put update the column no matter what it is?

UPDATE TableName
SET ColumnName = '777'

You could introduce a condition

UPDATE TableName
SET ColumnName = '777'
WHERE whatever = whatever

Steve

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 23, 2008 Jun 23, 2008

Copy link to clipboard

Copied


>You want to put update the column no matter what it is?

I really just want to delete everything in that column but I was also
curious about a "Wildcard" too.

So first, how could I delete all in one column

Second, how can I UPDATE all those that are LIKE '%666%' to '777' ?

Thanks

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 23, 2008 Jun 23, 2008

Copy link to clipboard

Copied

By the way, I'm using query analyzer to do this.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 23, 2008 Jun 23, 2008

Copy link to clipboard

Copied

DELETE incl optional WHERE clause:

DELETE ColumnName
FROM YourTable
(WHERE ColumnName = 'YourVal')

UPDATE:

UPDATE YourTable
SET ColumnName = '777'
WHERE ColumnName LIKE '%666%'

Pat.

"Art" <lee_*nospamification@artjunky.com> wrote in message
news:g3ojuh$4ns$1@forums.macromedia.com...
>
> >You want to put update the column no matter what it is?
>
> I really just want to delete everything in that column but I was also
> curious about a "Wildcard" too.
>
> So first, how could I delete all in one column
>
> Second, how can I UPDATE all those that are LIKE '%666%' to '777' ?
>
> Thanks
>


Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 24, 2008 Jun 24, 2008

Copy link to clipboard

Copied

Pat Shaw wrote:

> DELETE ColumnName
> FROM YourTable
> (WHERE ColumnName = 'YourVal')

So this will delete all the entries in ColumnName. I just wanted to make
sure that it won't delete the column itself.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 25, 2008 Jun 25, 2008

Copy link to clipboard

Copied

LATEST
Sorry Art, when I look again I have given you bad information here. It is
not possible to perform this at column level with a DELETE. To do this you
will have to use an UPDATE statement, either setting the column to an empty
value ie '' or to NULL (if the column is nullable).

For your information, when you issue a DELETE command in T-SQL, the
statement cannot modify the table structure in any way, it purely effects
the data within it. To alter/remove the columns etc you would need to use an
ALTER TABLE statement.

Pat.

"Art" <lee_*nospamification@artjunky.com> wrote in message
news:g3r6fp$1ue$1@forums.macromedia.com...
> Pat Shaw wrote:
>
>> DELETE ColumnName
>> FROM YourTable
>> (WHERE ColumnName = 'YourVal')
>
> So this will delete all the entries in ColumnName. I just wanted to make
> sure that it won't delete the column itself.


Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines