Skip to main content
Inspiring
June 23, 2008
Question

Query?

  • June 23, 2008
  • 7 replies
  • 321 views
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?
This topic has been closed for replies.

7 replies

Inspiring
June 25, 2008
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.


Inspiring
June 24, 2008
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.
Inspiring
June 24, 2008
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
>


Inspiring
June 23, 2008
By the way, I'm using query analyzer to do this.
Inspiring
June 23, 2008

>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

Inspiring
June 23, 2008
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
Inspiring
June 23, 2008
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 %%?