| Author |
Topic |
|
venkatv
Starting Member
4 Posts |
Posted - 2009-09-24 : 21:50:48
|
| Hi All,Can any one help me out on my requirement.I have a table "Phone" which has 3 columnssaycolA, colB, colC where colA, colB are associated as many-to-many.Ex:colA colB54 1954 1556 2058 2058 1858 16what i need is based on the association i need to update the colC value as 1,2,3 soo onthat is:colA colB colC54 19 154 15 256 20 1 58 20 158 18 258 16 3It would be a great favour if any one help me out on this.--Venkat. |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-09-25 : 00:57:48
|
| update tset colc = s.ridfrom tablename tinner join (select row_number()over(partition by cola order by cola) as rid ,* from tablename)son s.cola = t.cola and s.colb = t.colb |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-09-25 : 01:04:23
|
| HI try this once,select id identity(int,1,1),* into #temp from Tablenameselect *,(select count(*) from tablename where id<= t.id and t.cola = cola ) from tablename t |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-09-25 : 03:19:21
|
| Which version of SQL Server are you using?MadhivananFailing to plan is Planning to fail |
 |
|
|
venkatv
Starting Member
4 Posts |
Posted - 2009-09-25 : 11:17:51
|
quote: Originally posted by bklr update tset colc = s.ridfrom tablename tinner join (select row_number()over(partition by cola order by cola) as rid ,* from tablename)son s.cola = t.cola and s.colb = t.colb
Thanks bklr for your very quick response, I tried executing the query, but its failing at ROW_NUMBER, Its my fault that i didn't mention before that we are using MS SQL Server 2000. (where the database properties compatibility is set to 80).do we have any other alternate solution for MS SQL Server 2000.Regards,Venkat. |
 |
|
|
venkatv
Starting Member
4 Posts |
Posted - 2009-09-25 : 11:19:27
|
quote: Originally posted by Nageswar9 HI try this once,select id identity(int,1,1),* into #temp from Tablenameselect *,(select count(*) from tablename where id<= t.id and t.cola = cola ) from tablename t
Hi Nageshwar,Thanks for your reply, the identity is not working, as i am using MS SQL Server 2000, thats my fault i didnt mention before.Please respond if we have any alternate solution with 2000.Regards,Venkat. |
 |
|
|
venkatv
Starting Member
4 Posts |
Posted - 2009-09-25 : 11:20:17
|
quote: Originally posted by madhivanan Which version of SQL Server are you using?MadhivananFailing to plan is Planning to fail
Hi Madhavan,Thanks for reply, I am using MS SQL Server 2000.Regards,Venkat. |
 |
|
|
winterh
Posting Yak Master
127 Posts |
Posted - 2009-09-25 : 11:28:42
|
| What version of SQL are you using?[ /fail at query] |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-09-25 : 11:30:26
|
As far as I can see OP has already answered that question 3 times in this very thread..quote: Originally posted by winterh What version of SQL are you using?[ /fail at query]
|
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|