Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
pvong
Yak Posting Veteran
58 Posts |
Posted - 2011-05-13 : 16:09:47
|
| Example TableA B1 Joe@email2 Joe@email3 Joe@email1 Smith@email2 Smith@email1 Jane@email1 Kyle@email2 Kyle@emailBasically, I have a table column B. I would like to insert a number in COL A for each email. So Joe's emails shows up 3 times so I have 1-3. Smith@email has 2 emails so I have 2 counts in COL A. Jane@email has 1 so it just has a value of 1. How do I populate this information in Col A based on the list from Col B?Thanks!------------------------------Using VS2010 / Learning in VB.Net / Win2008 R2 / SQL 2008 R2Be kind to the newbies because you were once there. |
|
|
Skorch
Constraint Violating Yak Guru
300 Posts |
Posted - 2011-05-13 : 16:58:27
|
Try this:declare @t table (email varchar(20))insert @t (email)select 'Joe@email' union allselect 'Joe@email' union allselect 'Joe@email' union allselect 'Smith@email' union allselect 'Smith@email' union allselect 'Jane@email' union allselect 'Kyle@email' union allselect 'Kyle@email'select row_number() over(partition by email order by email) as seq, *from @t Some days you're the dog, and some days you're the fire hydrant. |
 |
|
|
|
|
|