locked
How to implement distinct clause with time. RRS feed

  • Question

  • User1052662409 posted

    Hi All,

    I am creating user log report.

    here I am inserting the data using procedure.

     BEGIN
    		   set @login_time=DATEADD(MI, 330, SYSUTCDATETIME())
    		   INSERT INTO tblUserAudit (user_name,login_time,location,module_visited,browser_name)
    		   VALUES (@user_name,@login_time,@location,@module_visited,@browser_name)
    
    		   END

    In my data base some how I get double entry with a small difference of time (It may be greater difference if a user login in 2 times or n number of times), I am unable to understand how this difference comes. like in this case it is "2019-12-19 12:37:36.783" and "2019-12-19 12:37:36.457". I don't know why even I am just calling my methods only for ones.

    Then I select the data using below query .

      SELECT  DISTINCT  log_id, user_name,login_time,location,module_visited,browser_name
      FROM tblUserAudit
      ORDER BY login_time desc

    But distinct doesn't work for time. See the image below. And see the records marked with the red 

    tt

    Please give share the solution how can I restrict it to insert the duplicate records OR how to use distinct with the above query.

    Please suggest

    Thursday, December 19, 2019 8:51 AM

Answers

  • User77042963 posted

    Most likely your application execute your code twice. You should handle the case from your application.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 19, 2019 5:12 PM

All replies

  • User77042963 posted

    Most likely your application execute your code twice. You should handle the case from your application.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 19, 2019 5:12 PM
  • User753101303 posted

    Hi,

    What if you try to double click the login button ?

    Thursday, December 19, 2019 5:38 PM
  • User77042963 posted

    You need to handle this case in your click event code.

    Thursday, December 19, 2019 6:10 PM