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 |
|
pelegk2
Aged Yak Warrior
723 Posts |
Posted - 2006-05-08 : 05:49:12
|
| i have rows that contains diffrent id number of pepole lik this234645,234823456,234,12378 01/01/2000234645,23999,2984534,12378 01/01/2000where in each row no id appears more then once!and so oni need to do 2 things :1)to get a list of all the companies in the rows and the number of times they appear.2)to do the same but with a time limit (which i think after (1) is solvded this will be easythnaks i nadvancepelegIsrael -the best place to live in aftr heaven 9but no one wan't to go there so fast -:) |
|
|
pootle_flump
1064 Posts |
Posted - 2006-05-08 : 06:03:44
|
HiThis would be trivial in the extreme if the data was normalised:http://r937.com/relational.htmlIs there any reason it isn't or cannot be made to be so? If not the solution will be convoluted and inefficient. I wouldn't fancy writing it for starters HTH |
 |
|
|
pelegk2
Aged Yak Warrior
723 Posts |
Posted - 2006-05-08 : 06:24:46
|
| i agree i shoulb be normalisedbut i have recived it like this so i cant change it now its very vry complicated to do so :(so how can isolve this?Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:) |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-05-08 : 08:24:53
|
| Apply thishttp://www.nigelrivett.net/SQLTsql/f_GetEntryDelimiitted.htmlthenselect id, c = dbo.f_GetEntryDelimiitted(fld, 1, ',', 'N')union allselect id, dbo.f_GetEntryDelimiitted(fld, 2, ',', 'N')union allselect id, dbo.f_GetEntryDelimiitted(fld, 3, ',', 'N')...up to the max will give you a normalised structure thenselect c, count(*)from(select id, c = dbo.f_GetEntryDelimiitted(fld, 1, ',', 'N')union allselect id, dbo.f_GetEntryDelimiitted(fld, 2, ',', 'N')union allselect id, dbo.f_GetEntryDelimiitted(fld, 3, ',', 'N')...) agroup by cI think this might come up against the bug with using a function to form a derived table but give it a go.It won't be quick.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|
|
|