Wednesday, March 7, 2012

getting latest or max value from primary key field.

Hi I have a table like
*******************
*pri key * varchar (20)*
********************
* 1 * tom *
* 2 * joe *
* 3 * paul *
Need a query that gets the highest pri key value. thanks.
mabye something like
SELECT field1
FROM table
WHERE field1 IS MAX
I did have a simple count but in working with the stored procedure that
writes to this table the pri key value got skipped for a few entries, so
count comes up short by a few.
Paul G
Software engineer.
Hi
SELECT MAX(field1)
FROM table
Regards
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Paul" <Paul@.discussions.microsoft.com> wrote in message
news:01998100-B507-4F3C-9DE3-FC4E14C3EE2D@.microsoft.com...
> Hi I have a table like
> *******************
> *pri key * varchar (20)*
> ********************
> * 1 * tom *
> * 2 * joe *
> * 3 * paul *
> Need a query that gets the highest pri key value. thanks.
> mabye something like
> SELECT field1
> FROM table
> WHERE field1 IS MAX
> I did have a simple count but in working with the stored procedure that
> writes to this table the pri key value got skipped for a few entries, so
> count comes up short by a few.
> --
> Paul G
> Software engineer.
|||ok thanks this is what I was looking for.
"Mike Epprecht (SQL MVP)" wrote:

> Hi
> SELECT MAX(field1)
> FROM table
> Regards
> --
> Mike Epprecht, Microsoft SQL Server MVP
> Zurich, Switzerland
> IM: mike@.epprecht.net
> MVP Program: http://www.microsoft.com/mvp
> Blog: http://www.msmvps.com/epprecht/
> "Paul" <Paul@.discussions.microsoft.com> wrote in message
> news:01998100-B507-4F3C-9DE3-FC4E14C3EE2D@.microsoft.com...
>
>

No comments:

Post a Comment