none
Always getting the latest record ID in database RRS feed

  • Question

  • My scenarios:
    - currently i want to develop system that can notify only latest inserted data. For doing that i use the SqlDependency method. Besides that, i want to calculate the total ID ( i name my ID as EventID) in the database since different total of EventID brings different solution.
    For example:
    if (count(EventID) > 1 )
     --> doing something
    with the condition, only latest EventID will be selected.
    How do i suppose to do that?
    Please help me..

    Thanks in advance
    Jac
    Thursday, August 16, 2007 4:26 AM

All replies

  • You can get the greatest id:

    SELECT MAX(eventid) FROM table

    You can count the number of rows:

    SELECT COUNT(*) AS numberOfRows FROM table


    Thursday, August 16, 2007 5:49 AM
  • thanks...i have done that before but since the query is not returning me notification of newly inserted data so it cant be used. Here,what i mean is the database connection is always on.If there is a transaction made, it will notify me...

    thanks
    Thursday, August 16, 2007 6:29 AM
  • In that case i would recommend to have a look at 'Sql Server Notification Services'...
    Thursday, August 16, 2007 7:09 AM