Normal Topic Remove result set  duplicate records (Read 861 times)
tcgeo
Full Member
***
Offline



Posts: 278
Location: Traverse City, Michigan
Joined: May 13th, 2008
Remove result set  duplicate records
Nov 20th, 2010 at 9:09pm
Print Post Print Post  
I’m using the @XResultSetSearch commands to return a result set.
Is there a way to remove duplicate records from the result set based on addresses in an address LE, so that @PopupChoiceList only shows one listing for each address?

I tried playing around with @LoadDuplicateSpec and RunDuplicateSpec(0),not sure if they are viable options or not.

Thanks for the help.

  
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Remove result set  duplicate records
Reply #1 - Nov 21st, 2010 at 9:40pm
Print Post Print Post  
One way is to loop through the result set, building a string array of the addresses. Then, use @UniqueStringArray(@SortStringArray( MyStringArray, 0)) to prep it for @PopupChoiceList. You will most likely want to sort the list since @PopupChoiceList doesn't sort either (just like it doesn't remove duplicates). If you do sort, be sure to let that run before removing the duplicates with @UniqueStringArray, because I have found that it's 6 times faster to sort first, then run the unique function.

Another way is to use this one-liner with @XListValues as the source:
@PopupChoiceList(@UniqueStringArray(@SortStringArray(@XListValues(@Fn, "FormName!LE_Name"), 0)), "Make a Selection")
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
tcgeo
Full Member
***
Offline



Posts: 278
Location: Traverse City, Michigan
Joined: May 13th, 2008
Re: Remove result set  duplicate records
Reply #2 - Nov 21st, 2010 at 10:51pm
Print Post Print Post  
Thank you for the reply Carl, and thank you for the ideas, I'll give those a try!

Brandon


  
Back to top
IP Logged
 
tcgeo
Full Member
***
Offline



Posts: 278
Location: Traverse City, Michigan
Joined: May 13th, 2008
Re: Remove result set  duplicate records
Reply #3 - Nov 22nd, 2010 at 7:23pm
Print Post Print Post  
A little more help on this please…..

The code below returns a @popupchoice list that looks like this:

Location – LocAddress
Location – LocAddress
Location – LocAddress

Several of the LocAddresses are identical. I just can't seem to figure out how or where to incorporate your code Carl; @UniqueStringArray(@SortStringArray( MyStringArray, 0)) so that the result would remove all but one of the duplicate Locations if the LocAdresses are the same.

Thanks for your help.

Brandon

Code
Select All
vRS = @XResultSetSearch(@FN,"Customers", SEARCH_MODE_OR, SEARCH_SYNTAX_QA, "")  
	If vRS > -1
	{
		vCount = @XResultSetTotal(vRS)
		If vCount = 0
		{
			@MsgBox("No matching records.", "", "")
		}
			vList = ""
			XResultSetSort(vRS, "Location:-1")
			For vLoop = 1 To vCount
				XResultSetCurrentPosition(vRS, vLoop)
				vLocation = @XResultSetValue(vRS, "Location")
				vLocAddress = @XResultSetValue(vRS, "LocAddress")
				vList = vList + vLocation + " " + "-" + " " + vLocAddress + ";"

			Next
				PopupSelectPosition(3, 108, 105)
				vChoice = @PopupChoiceList(vList, "SELECT A LOCATION")
				vGroup = @Left(vChoice, @Instr(vChoice, "-")-1)
 

  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Remove result set  duplicate records
Reply #4 - Nov 22nd, 2010 at 7:51pm
Print Post Print Post  
You're already sorting the resultset itself, so you shouldn't need to sort again. After the Next that ends your For loop, put:

vList = @UniqueStringArray(vList)

... to strip the duplicates from your list.

Also, you might want to use an Else to make sure you don't pop up an empty list if there are no records in your resultset. You also want to wrap the line that sets vGroup in an If condition that makes sure the user picked something form the list instead of just hitting escape without making a selection. Otherwise, you will overwrite the value in vGroup when you may not want to.

If vChoice <> ""
{
   vGroup = @Left(vChoice, @Instr(vChoice, "-") - 1)
}
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
tcgeo
Full Member
***
Offline



Posts: 278
Location: Traverse City, Michigan
Joined: May 13th, 2008
Re: Remove result set  duplicate records
Reply #5 - Nov 22nd, 2010 at 10:01pm
Print Post Print Post  
Thank you very much Erika.

That works great, thank you. I wish I could figure out why I sometimes just can't make it work......and, I wish I had just half the brains you folks have!

I appreciate all of your help.

Have a good Thanksgiving!

Brandon
  
Back to top
IP Logged