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 |
|
M.E.
Aged Yak Warrior
539 Posts |
Posted - 2002-07-02 : 14:00:47
|
| select count(1) as record_count,Resource_entity_id, Resource_data_type, New_Interpretation_Date_Time, Applicable_Strat_Unit, New_Revised_Date_Timefrom resource_data_profile_txtgroup by Resource_entity_id, Resource_data_type, New_Interpretation_Date_Time, Applicable_Strat_Unit, New_Revised_Date_Timeorder by count(1)returns all records 1 record per group. So those columns combined make it each record in _txt uniqueselect Resource_entity_id, convert(int,'') as Resource_data_seq, Resource_data_type, New_Interpretation_Date_Time, Applicable_Strat_Unit, New_Revised_Date_Timeinto #resource_admin_tempfrom resource_data_profile_txtorder by Resource_entity_id, Resource_data_type, New_Interpretation_Date_Time, Applicable_Strat_Unit, New_Revised_Date_Timedeclare @new int, @last varchar(5000)select @new = 1, @last = 0update #resource_admin_tempset @new = Resource_data_seq = case when @last = Resource_entity_id then @new + 1 else 1 end, @last = Resource_entity_idselect count(47),Resource_Data_Seq,Resource_Entity_Idfrom #resource_admin_tempgroup by Resource_Data_Seq,Resource_Entity_Idorder by count(47) descthe select statement gives me 139 incidents where 2 records are assigned the same Resource_Data_Seq,Resource_Entity_Id. I've got no clue why it's doing that. select * from #resource_admin_temp where Resource_Data_Seq = 1and Resource_Entity_Id = '0855182101090'gives back 2 records that have different Applicable_Strat_Unit values. when they should have each been assigned a unique resource_data_seq for that record.Any ideas? Bleh, lunch time-----------------------Take my advice, I dare ya |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2002-07-02 : 14:11:24
|
quote: select count(1) as record_count,Resource_entity_id, Resource_data_type, New_Interpretation_Date_Time, Applicable_Strat_Unit, New_Revised_Date_Time from resource_data_profile_txt group by Resource_entity_id, Resource_data_type, New_Interpretation_Date_Time, Applicable_Strat_Unit, New_Revised_Date_Time order by count(1)
does not meanquote: returns all records 1 record per group. So those columns combined make it each record in _txt unique
tryselect count(*), Resource_entity_id, Resource_data_type, New_Interpretation_Date_Time, Applicable_Strat_Unit, New_Revised_Date_Time from resource_data_profile_txt group by Resource_entity_id, Resource_data_type, New_Interpretation_Date_Time, Applicable_Strat_Unit, New_Revised_Date_Time from resource_data_profile_txtgroup by Resource_entity_id, Resource_data_type, New_Interpretation_Date_Time, Applicable_Strat_Unit, New_Revised_Date_Time from resource_data_profile_txt group by Resource_entity_id, Resource_data_type, New_Interpretation_Date_Time, Applicable_Strat_Unit, New_Revised_Date_Time having count(*) > 1 This is why I asked you in the old thread what your PK was. The tricky update will only work if the temp table is ordered properly.<O> |
 |
|
|
M.E.
Aged Yak Warrior
539 Posts |
Posted - 2002-07-02 : 16:20:20
|
| Hmm, ended up being a logical error in the datadrop table #resource_admin_tempcreate table #resource_admin_temp(idcol int identity(1,1),Resource_entity_id varchar(15), Resource_data_seq int, Resource_data_type varchar(150), New_Interpretation_Date_Time datetime, Applicable_Strat_Unit varchar(150), New_Revised_Date_Time datetime)insert into #resource_admin_tempselect Resource_entity_id, convert(int,'') as Resource_data_seq, Resource_data_type, New_Interpretation_Date_Time, Applicable_Strat_Unit, New_Revised_Date_Timefrom resource_data_profile_txtorder by Resource_entity_id asc, Resource_data_type, Applicable_Strat_Unit descdeclare @new int, @last varchar(5000)select @new = 1, @last = 0update #resource_admin_tempset @new = Resource_data_seq = case when @last = Resource_entity_id then @new + 1 else 1 end, @last = Resource_entity_idFor some strange reason, which I'm still researching cause it just seems weird, the Applicable_Strat_Unit needed the keyword DESC for it to work. [edit]I added the incrementing IDCOL just for trouble shooting pruposes.. let me look at exactly what order the data was in [/edit]Problem solved... Thanks muchly for your help Page47-----------------------Take my advice, I dare yaEdited by - M.e. on 07/02/2002 16:25:46 |
 |
|
|
|
|
|
|
|