|
Acaila Apprentice
Joined: 30 Aug 2001 Posts: 187 Location: Netherlands
|
Posted: Tue Sep 04, 2001 11:23 am
Database & Duplicates |
For a while now I've been working with the Database feature. I have triggers set up to capture info from an identify perfectly, and put it into an item database. My problem arises when I import the items from a person I gave my triggers to (to update the database with items they have). On importing it just adds all items to my current database, and thus creates duplicates all oever the place. I tried making an alias to remove those duplicates. Butfor some reason I can't fanthom it won't delete anything. Here's what I've got so far:
#DBFIRST
@PreviousName = &Name
@PreviousLevel = &Level
@ItemsRemoved = 0
#LOOPVIEW {#IF (&Name = @PreviousName AND &Level = @PreviousLevel) {
#DBDelete %rec
@PreviousName = &Name
@PreviousLevel = &Level
#ADD ItemsRemoved (1)
} {
@PreviousName = &Name
@PreviousLevel = &Level
}}
#SAY @ItemsRemoved duplicate items removed
Basically I tell it to compare each &Name and &Level field with the previous record. Any that have the same name and the same level should be removed.
Please tell me what I did wrong, or give other suggestions.
Acaila |
|
|
|
Acaila Apprentice
Joined: 30 Aug 2001 Posts: 187 Location: Netherlands
|
Posted: Tue Sep 04, 2001 1:59 pm |
I also tried something else, this seemed better to me, but that doesn't do anything either:
@ItemsRemoved = 0
#LOOPVIEW {#IF (&Name = &Name( %rec-1) AND &Level = &Level( %rec-1)) {
#DBDelete %rec
#ADD ItemsRemoved 1
} {}}
#SAY @ItemsRemoved duplicate items removed
The code in my previous note does increase @ItemsRemoved, but doesn't delete those duplicates it finds. This last piece of code doesn't even increase the @ItemRemoved variable.
I think it's just an error in syntax, but I don't know how else to write it.
Acaila |
|
|
|
Acaila Apprentice
Joined: 30 Aug 2001 Posts: 187 Location: Netherlands
|
Posted: Fri Nov 16, 2001 3:48 pm |
The above is a post I did a couple of months ago, trying to find a way how to remove duplicates in an item database. I solved it a while back, but never thought about posting it. But with the recent questions about item databases I'm posting it now for those people who are interested.
#ALIAS dbfix {
#VARIABLE ItemsRemoved 0
#DBFIRST
#WHILE (!%null( %rec)) {
#VARIABLE Record %rec
#DBNEXT
#WHILE (&Name = @Record.Name & &Level = @Record.Level) {
#DBDELETE @Record.Num
#ADD ItemsRemoved (1)
#DBNEXT
}
}
#SAY @ItemsRemoved duplicate items removed
#UNVAR Record
#UNVAR ItemsRemoved
Have your database open on the "All" field before you use the alias.
Acaila |
|
|
|
|
|