Click here to Skip to main content
Rate this: bad
good
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 22:55pm

1 solution

Rate this: bad
good
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!
  Permalink  
Comments
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:
http://msdn.microsoft.com/en-us/library/ms187748.aspx
 
http://msdn.microsoft.com/en-us/library/ms187928.aspx

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 130
4 DamithSL 105
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 18 Feb 2013
Copyright © CodeProject, 1999-2014
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