Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change data of a row

Status
Not open for further replies.

babeo

Technical User
Mar 30, 2000
398
CA
I want to change 1 character (the 3rd one) of 1 row in a database, and keep the rest of characters and other rows are original data, how can I do that?
eg: WIT3WIT to become WIT6WIT,
MTT4ABD to become MIT6ABD, and so on.
Thanks
 
Below is the basic syntax to change to 4th character of a column. Good luck!
Code:
UPDATE YourTable
SET YourColumn = LEFT(YourColumn, 3)
                 + '6'   --<--- 4th character changed to
                 + SUBSTRING(YourColumn, 5, LEN(YourColumn))

--John [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
Hi John,
Sorry to mention it: We use MSSQL Version 6.5,
So, I am not sure, the code you give me is for 2000 version or else, but I have syntax error when running it.
Could you rework it please? Thanks
 
It has been a while since I worked on 6.5, but I think that LEFT, LEN, and SUBSTRING were all valid functions. Try to get a SELECT statement working, then modify it to an UPDATE.

Code:
SELECT LEFT(YourColumn, 3)
       + '6'   
       + SUBSTRING(YourColumn, 5, LEN(YourColumn))
FROM YourTable

--John [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
Thank John,

I think LEFT function for version 2000, but not for 6.5, so here is my code, and it works.
Thank you very much for your initial help.
UPDATE YourTable
SET YourColumn = SUBSTRING(YourColumn, 1, 3)
+ '6' --<--- 4th character changed to
+ SUBSTRING(YourColumn, 5,3))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top