Click here to Skip to main content
11,707,470 members (73,163 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: SQL-Server-2008
Hi Frnds,
 I Have Table like this 
                          ID    Name
                        123156    A
                        123157    B
                        123158    C
                        125123    D
                        125124    E
I need to Update this table as follows
                           ID    Name
                        124156    A
                        124157    B
                        124158    C
                        125123    D
                        125124    E
Here Rows 1,2,3 Contains start id with 123 ie 3,i have to replace with 124 ie 4.... Have to replace 3 as 4.
Posted 17-Feb-13 21:55pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Would be a very bad idea to update ID's, but if you really must you can use LIKE or SUBSTRING for that. you first need to convert the ID to text, process it, and convert it back.

Good luck!
itsureshuk at 18-Feb-13 4:14am
please give some queries example
E.F. Nijboer at 18-Feb-13 5:01am
Have you tried something yourself? Please add the query you got so far and what you have tried. I'm more than willing to help out but ain't going to do your work.
itsureshuk at 18-Feb-13 5:46am
update tbName
set ColName= substr(ColName,3,1) || ’4′
where substr(ColName,3,1)=’3′;
E.F. Nijboer at 18-Feb-13 6:50am
Did you try to execute this query? There is no SUBSTR in SQL2008. Also, how did you come up with ColName?
itsureshuk at 18-Feb-13 10:23am
sorry SUBSTRING only
substr is oracle,,,We can pass column values in substring r not
E.F. Nijboer at 18-Feb-13 12:54pm
Not clear to me. Can you elaborate?
itsureshuk at 20-Feb-13 0:25am
You Can pass Columnname in Substring(Columnname,Start,Length)
E.F. Nijboer at 20-Feb-13 2:56am
Haven't you tried?
E.F. Nijboer at 18-Feb-13 6:52am
By the way, have a look here:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Mika Wendelius 220
1 Maciej Los 195
2 OriginalGriff 148
3 Sergey Alexandrovich Kryukov 145
4 chainerlt 110
0 OriginalGriff 9,198
1 Sergey Alexandrovich Kryukov 8,562
2 CPallini 5,189
3 Maciej Los 4,921
4 Mika Wendelius 3,856

Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 18 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100