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 9208939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:43:32+00:00 2026-06-18T00:43:32+00:00

I am trying to get the maximum ID from a database table and want

  • 0

I am trying to get the maximum ID from a database table and want to show it on win form load.
I am using the following query to get the maximum ID.

SELECT ISNULL(MAX(ID),0)+1  FROM StockMain WHERE VRDATE = '2013-01-30'

Above should have to return the maximum ID of today., e.g if I this statement is excutes for the first time it will return me the Value ‘1’. After saving first record on ID = ‘1’ it should give me MAX(ID) = ‘2’. But it returns me the value 1.

Any suggestion or solutions????

  • 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-06-18T00:43:34+00:00Added an answer on June 18, 2026 at 12:43 am

    Wild guess… but what data type is VRDATE? Does it include a time component, or is it just a date?

    If it includes a time component indicating when you saved the record, it won’t pass the VRDATE = '2013-01-30' check, since this defaults to a time of midnight. Since the times aren’t identical, they are not equal.

    Instead, try:

    SELECT ISNULL(MAX(ID),0)+1  
    FROM StockMain 
    WHERE VRDATE BETWEEN '2013-01-30' AND '2013-02-01'
    

    Next question… have you considered using an IDENTITY column instead of managing the ID values manually?

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

Sidebar

Related Questions

I'm trying to get the maximum date for an area_id from a 'review' table
I'm trying to get the maximum value of an integer field in a table.
Using classic asp, I am trying to query a SQL Server database like so:
I'm trying to get the max of column: select * from ( select col1,
I am trying to get some data from my database. This is my code
I am currently trying to get the following statement to work: SELECT t1.id, t1.row2
I am trying to get a list of all columns from a table with
I'm trying to write a query which will get the maximum scores for the
I am using iOS 5.0 and I'm trying to get a value from my
Hey guys, Im trying to get the maximum number of days in a database

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.