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 |
|
theroversreturn
Starting Member
12 Posts |
Posted - 2011-11-01 : 06:33:51
|
| Hi, I have a table which has record_ids and versions. I also have a field in the table called user_id. For all versions of the same record_id the user_id should be the same. Unfortunatley there was a little issue whereby the user_id was changed in some records and I need to find these records. The set up would be like below:-Table====Record_id Version User_id234443 1 7234443 2 7234444 1 12234445 1 23234445 2 23234445 3 100In the above example record_id 234445 would be what I'd like my query to return.Thanks in advance |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-11-01 : 06:37:45
|
| select Record_id, count(distinct user_id), max(user_id), min(user(id), count(*)from tblgroup by Record_idhaving max(user_id) <> min(user_id)==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-01 : 06:38:36
|
| how do you determine which should be correct userid? do you have a master table for this user_id values associated to each record_id? what if you've two records one each with 23 and 100 for 234445. which one will you return in that case?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
theroversreturn
Starting Member
12 Posts |
Posted - 2011-11-01 : 06:42:02
|
| Perfect that you very much |
 |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-11-01 : 06:42:18
|
| The op said the record id was wanted not the user_id - look at my query.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
theroversreturn
Starting Member
12 Posts |
Posted - 2011-11-01 : 06:44:14
|
| All I wanted returned was the record_id of those records which had a variance in user_id which was exactly as Nigels query returned. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-01 : 07:17:54
|
quote: Originally posted by theroversreturn All I wanted returned was the record_id of those records which had a variance in user_id which was exactly as Nigels query returned.
oh ok.. I understood------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|