Results 1 to 3 of 3

Thread: asp classic find duplicate record in database

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2019

    asp classic find duplicate record in database

    If I have a user that selects a product that is already in their account that they purchased 90 days or less ago, I want to notify them that it is a duplicate purchase. I don't want to stop the duplicate purchase, I just want to as a curtsey, let them know that it is a duplicate within that 90 day period.

    This code is not working and I am having a difficult time with the logic.

    I am using ASP Classic. Any help would be appreciate.

    dim dat90
    dim AlreadyPurchased
    AlreadyTaken = false
    dat90 = dateadd("d", -90, now) '90 days ago
    Do Until objRS.EOF
        if cstr(objRS("ProductName")) = objRS("ProductName") and cdate(objRS("PurchasedDate")) <= dat90 then
            AlreadyPurchased = true
            exit do
        end if
    Then the response.write to the page inside the loop would be:

    <%=objrs("ProductName")%> <% if AlreadyTaken then%> Already Purchased<%end if%>

  2. #2
    Join Date
    Feb 2012
    West Virginia

    Re: asp classic find duplicate record in database

    Well you do not seem to be checking the date correctly so that may be your problem.

    That said rather than looping though a recordset you may be better off using a query.
    Also note that the customer ID should be part of the test and rather than product name a product ID would make more sense.

    Something roughly like
    Select PurchaseDate From Transactions where CustomerID=TheCustomerID And ProductID=TheProductID And PurchaseDate > dat90

  3. #3
    Lively Member
    Join Date
    Jan 2018

    Re: asp classic find duplicate record in database

    You're switching between AlreadyTaken and AlreadyPurchased.
    Don't forget to use Option Explicit at the top of any code file.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width