I did something similar to this recently. This isn’t jquery
Just a start, working just with the names
var codes = ['1 CHLIB0211*','1 CHLIB0211*','1 PEPPM0311*','1 CHLIB0211*','1 PEPPM0311*','4RIA1111'];
// need to group the same codes together first using sort
codes.sort(); // ["1 CHLIB0211*", "1 CHLIB0211*", "1 CHLIB0211*", "1 PEPPM0311*", "1 PEPPM0311*", "4RIA1111"];
console.log(codes.filter(function(val, i , arr){
if (val !== arr[i - 1]) return true; // if current index not the same as last store it
})); // ["1 CHLIB0211*", "1 PEPPM0311*", "4RIA1111"]
Is there a special reason you want to do this using javascript instead of ASP? It seems a bit weird to me to let ASP send too many information and then throw out out stuff you don’t want with javascript. If you filter the duplicates in ASP you get less data traffic and javascript doesn’t have to process anything, making the script faster on two accounts.
And yes, I do realize the ASP script will probably get slightly slower, but I’m pretty sure it’s worth it
Is there a special reason you want to do this using javascript instead of ASP? It seems a bit weird to me to let ASP send too many information and then throw out out stuff you don’t want with javascript. If you filter the duplicates in ASP you get less data traffic and javascript doesn’t have to process anything, making the script faster on two accounts.
And yes, I do realize the ASP script will probably get slightly slower, but I’m pretty sure it’s worth it
I see what you mean, it would be even better if this was taken care of in the stored procedure itself.
Now i know this is not an SQL related thread but i will post it anyway, just to show how it would be possible to take care of things like this in the back end rather than client side.
This is my SQL query:
DECLARE @AgentID int = 515, @SearchStr varchar(max) = 'CHLI'
SELECT DISTINCT
Q.ID,
Q.Code
FROM Quote Q
LEFT JOIN Transport T ON Q.ID = T.QuoteID
LEFT JOIN Route R ON T.RouteID = R.ID
INNER JOIN Lookup L ON Q.TID = L.ID
WHERE Q.Depart >= GETDATE()
AND Q.SID IN (2500, 2550, 2540)
AND Q.Code LIKE ISNULL('%' + NULLIF(@SearchStr,'') + '%','%')
AND Q.ID NOT IN (SELECT QuoteID FROM TourAgent WHERE AgentID = @AgentID)
AND (L.Name <> 'Pot' OR R.Code = '')
GROUP BY Q.Code, Q.ID, Q.SID
ORDER BY Code
I think i need to somehow check it here, because currently i am trying to do it in the ASP which to be honest i know is not the best option…