Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7183393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:58:12+00:00 2026-05-28T17:58:12+00:00

I have a table that has the following columns: GRVLID GRID Timein Timeout This

  • 0

I have a table that has the following columns:

GRVLID
GRID
Timein
Timeout

This table is part of a visitor tracking system.

There is another table that holds each visitor’s information. This table keeps track of each time the visitor logs in and out.

GRVLID is the unique record identifier. GRID is the visitor identifier number. Each visitor has their own GRID number. Timein is the datetime when the visitor logged in. Timeout is the datetime when the visitor logged out.

Every time a visitor logs in, a new record is created. So it would be possible to have multiple records with the same GRID number. The GRVLID number is unique and just increments as new records are added.

What I need is an update-set-where statement that updates the record that has the highest GRVLID number for a given GRID number. I tried doing:

update database
set [TimeOut] = @p_timeOut
where (GRID = @p_GRID and MAX(GRVLID))

but that doesn’t seem to play nice with MSSQL. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:58:13+00:00Added an answer on May 28, 2026 at 5:58 pm

    I think what you’re looking for is more like this:

    update database
    set [TimeOut] = @p_timeOut
    where GRID = @p_GRID 
    and GRVLID = (select MAX(GRVLID) from database WHERE where GRID = @p_GRID)
    

    There are more efficient ways to re-write this query, but if performance isn’t a concern then this will work fine and it’s easy to understand.

    P.S. I hope your table really isn’t named “database”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pictures table that has the following columns: PICTURE_ID int IDENTITY(1000,1) NOT
I have a table that has the following columns Id ForeignKeyId AttributeName AttributeValue Created
I have a cat table that has the following columns: cat_id | name |
I have a table called trends_points , this table has the following columns: id
i have a table that has the following columns: Team Region Person Name and
Hi all I have a 'widget' table that has the following columns: widget, action,
I have an table in my MySql database that has the following columns: -
I have a table that has following columns id store_id store_name id and store_id
Say I have a table that has the following columns: AutoID (PK, int not
I have a DB table users that has the following columns: id, clan_id, experience

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.