[Solved] SQL SELECT REPLACE

Hi All,
I had a query related to sql select update replace command.

i have a table named clusters and it looks like this

name                      model    characteristics
sample1.1                +123       parent
sample1.2                -456       clone
sample1.3                +122        clone
sample1.4                 +12        parent
sample1.5                 -14         parent
sample1.6                 -12         clone
sample2.1                 +45          parent

I want all my model values to be changed to +1 and -1
whichever model number are postive have to be +1 and whichever model number are negative have to be -1.
The table should look like this

clusters

name             model        characteristics
sample1.1       +1            parent
sample1.2       -1             clone
sample1.3       +1            clone
sample1.4       +1            parent
sample1.5       -1             parent
sample1.6       -1             clone
sample2.1       +1             parent

Is it possible using a select replace and update statement?
Please do help

Thanks !!
Sonia

Try like...

 select test1.*, case when sign(model)=1 then 1 else -1 end from test1 
update test1 set MODEL=case when sign(model)=1 then 1 else -1 end
 

Thanks!!it worked!!! :slight_smile:
:slight_smile:

I see no reason to delete your post, you asked a question and got a useful answer, future people with the same question may find this thread useful.

What about records that have "model" value 0 ?
If you want to update those to 0 (in other words, keep them as they are), or if you are sure such values won't occur in your data, then your UPDATE statement could be simply -

update clusters set model = sign(model);

tyler_durden

worked!! :slight_smile: