0

I want to rename several values on my table.

I just want to rename multi rows in a column of a table in my database :

SJ.10.06.000001
SJ.10.06.000002
SJ.10.06.000003
SA.10.06.000001
SB.10.06.000002

etc into this value :

SJ.09.06.000001
SJ.09.06.000002
SJ.09.06.000003
SA.09.06.000001
SB.09.06.000002

My SQL :

Update dbo.Deposito 
set nomor sj.09... 
where no rekening sj.10...

and I've got this :

Update dbo.Deposito 
set nomor sj.09... 
where no rekening sj.10...

Error

[Err] 42000 - [SQL Server]Incorrect syntax near 'sj'.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

1

try this....

UPDATE dbo.Deposito 
 SET nomor =  REPLACE(nomor, '.10.', '.09.')
WHERE SUBSTRING(nomor, 4, 2) = '10'
M.Ali
  • 67,945
  • 13
  • 101
  • 127
0

I think you can do this with substring too, but I could not remember the correct syntax, so I think you should try this.

It updates the values based on the 3rd and 4th characters in your table, so it exchanges 10 to 9, if that's what you are after.

There are a lot of ways to achieve this, it's just one of them.

update

I have tested this locally and it works.

UPDATE
    dbo.Deposito
SET
    nomor = REPLACE(nomor,'.10.','.09.')
WHERE
    substring(nomor,4,2) = '10'
Alex Szabo
  • 3,274
  • 2
  • 18
  • 30