[ASP & SQL] Method to ensure no duplicate rows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • viki1967
    Contributor
    • Oct 2007
    • 263

    [ASP & SQL] Method to ensure no duplicate rows

    Hi all.

    In the one file excel I have this situation:

    Code:
    ID	DATE		HOUR		NAME
    [b]1	2008-06-21	03:03:10	PAUL[/b]
    2	2008-06-21	03:33:10	PAUL
    3	2008-06-21	04:03:10	PAUL
    
    [b]4	2008-06-21	06:03:10	PAUL[/b]
    5	2008-06-21	06:33:10	PAUL
    6	2008-06-21	07:03:10	PAUL
    
    [b]7	2008-06-21	05:25:00	JANE[/b]
    8	2008-06-21	05:45:45	JANE
    9	2008-06-21	06:15:00	JANE
    
    [b]10	2008-06-21	08:25:00	JANE[/b]
    11	2008-06-21	08:45:45	JANE
    12	2008-06-21	09:15:00	JANE
    In BOLD the lines to be registered in the db mysql, the others lines excluded from registration...

    Not register records with HOUR value time of -1 hrs. the first hour .... its possible with ASP ?
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    In ASP you would do something like this:
    [code=asp]if dateDiff(firstD ateTime, secondDateTime, "h")< 1 then
    response.write "You are not allowed to punch in until 1 hour following " & firstDateTime
    else
    'add the record
    end if[/code]Let me know if this helps.

    Jared

    Comment

    • viki1967
      Contributor
      • Oct 2007
      • 263

      #3
      Originally posted by jhardman
      In ASP you would do something like this:
      [code=asp]if dateDiff(firstD ateTime, secondDateTime, "h")< 1 then
      response.write "You are not allowed to punch in until 1 hour following " & firstDateTime
      else
      'add the record
      end if[/code]Let me know if this helps.

      Jared
      Hi Jared and thanks x your reply... but I dont understand...

      My code ASP this is:

      [PHP]PercorsoCSV = "D:\Inetpub\www root\UploadFold er\file.csv " "

      Set objFSO = Server.CreateOb ject("Scripting .FileSystemObje ct")
      strURL = percorsoCSV

      Set objFile = objFSO.OpenText File(strURL)
      objFile.SkipLin e()

      Do While Not objFile.AtEndOf Stream

      strText = objFile.readLin e
      arrText = split(strText, ",", 17)

      Query = " SELECT (DATA + ORA) DATA_ORA "
      Query = Query & " FROM "
      Query = Query & " tbl "
      Query = Query & " WHERE "
      Query = Query & " DATA = " & formatDBDate(re place(arrText(2 ), """", ""), "mysql") & " "

      Set objRS = Server.CreateOb ject("ADODB.Rec ordset")
      objRS.open Query, cn

      If Not objRS.EOF then

      dataOra = objRS("DATA_ORA ")

      Do While Not objRS.EOF

      If objRS("DATA_ORA ") > DateAdd("h", 1, dataOra) then

      strSql = "INSERT INTO "
      strSql = strSql & " tbl ( ... ) "
      strSql = strSql & " VALUES "
      strSql = strSql & " ( ... ) "
      cn.execute(strS ql)

      objRS.movenext
      end if
      Loop

      End If
      Loop

      objFile.Close()
      Set objFile = Nothing

      cn.Close()
      Set cn = nothing [/PHP]

      Comment

      Working...