| Author |
Topic |
|
sql9999
Starting Member
2 Posts |
Posted - 2007-11-05 : 10:30:25
|
| HiI am trying to replace contents of all columns field contents with unique members. Can you share your thoughts on how this can be achieved?e.g. if the table containsJohn, Lewis, London, 200, 500David, Jones, New York, 500, 400with2,2,1,200,5001,1,2,500,400And in a separate table, I need 0,1,John0,2,David1,1,Jones1,2,Lewis,2,1,London2,2 New YorkThanksBobby |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-11-05 : 10:45:33
|
don't understand. Can you explain how to get from e.g. if the table containsJohn, Lewis, London, 200, 500David, Jones, New York, 500, 400with2,2,1,200,5001,1,2,500,400 TO0,1,John0,2,David1,1,Jones1,2,Lewis,2,1,London2,2 New York Please also post your table DDL KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
sql9999
Starting Member
2 Posts |
Posted - 2007-11-05 : 10:54:47
|
| Thanks for your quick reply.If you sort each column in ascending order you will find this order.0,1,David ( 0 - Column Number, 1 - Unique Number and then description)0,2,John 1,1,Jones1,2,Lewis,2,1,London2,2 New YorkOnce the unique numbers are obtained, I need to replace the table contents with the unique numbers.. i.e. changing the current table from John, Lewis, London, 200, 500David, Jones, New York, 500, 400to 2,2,1,200,5001,1,2,500,400This is an imaginary table at the moment, so there is no DDL. Strings are just NVARCHAR (255).. |
 |
|
|
Will H
Yak Posting Veteran
56 Posts |
Posted - 2007-11-05 : 13:05:18
|
| I think all you need is an update command. You'll have to join each column multiple times, though. Table Test1:id1 id2 Descr0 1 David0 2 Jones1 1 John1 2 Lewis2 1 London2 2 New YorkTable Test2:Text1 Text2 Text3John Lewis LondonDavid Jones New YorkUPDATE fSET f.Text1 = g1.Id2, f.Text2 = g2.Id2, f.Text3 = g3.Id2FROM test2 f JOIN test1 g1 on f.Text1 = g1.Descr JOIN test1 g2 on f.Text2 = g2.Descr JOIN test1 g3 on f.Text3 = g3.DescrOf course, this means that you'd be storing ints in varchar format...---------------------------------------------------------SSRS Kills Kittens. |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-11-05 : 19:59:37
|
quote: This is an imaginary table at the moment, so there is no DDL. Strings are just NVARCHAR (255)
Then give us a temp table with the imaginary structure and the imaginary sample data and imaginary expected output.see http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2007-11-06 : 09:20:27
|
And Imagine normalizing the data first. [Signature]For fast help, follow this link:http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspxLearn SQLhttp://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
|
|
|