|
-
Jun 12th, 2008, 04:26 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] How to get Max Record
I contains a lot of reference number
The list of number is
PC/120608-1
PC/120608-2
PC/190408-1
How do I return the value is PC/120608-2 by using SQL Query and Visual basic sorting ?
Where there is no hope, there can be no endeavor.
There are two ways of rising in the world, either by your own industry or by the folly of others.
-
Jun 12th, 2008, 05:13 AM
#2
Re: How to get Max Record
What do you really want to accomplish? Return just one record using WHERE condition column = 'PC/120608-2'? Or sort the records?
-
Jun 12th, 2008, 05:15 AM
#3
Thread Starter
Hyperactive Member
Re: How to get Max Record
the record returned from query is sort of records.
THANKS
Where there is no hope, there can be no endeavor.
There are two ways of rising in the world, either by your own industry or by the folly of others.
-
Jun 12th, 2008, 06:22 AM
#4
Re: How to get Max Record
Take a look at ORDER BY clause.
-
Jun 12th, 2008, 07:42 AM
#5
Re: How to get Max Record
A SQL query like this should return what you want.
Code:
SELECT TOP 1 *
FROM YourTable
ORDER BY [reference number] DESC
-
Jun 12th, 2008, 07:42 PM
#6
Thread Starter
Hyperactive Member
Re: How to get Max Record
I had tried to use order by clause initially.
The return would be asc = PC/120608-1
DESC = PC/190408-1
PC/ Is a fixed, 120608 is date, -1 is counter of reference number of that date..
So the largest value i would like to return is PC/160608-2
thanks for help
Where there is no hope, there can be no endeavor.
There are two ways of rising in the world, either by your own industry or by the folly of others.
-
Jun 12th, 2008, 07:53 PM
#7
Re: How to get Max Record
I don't think you can do that with SQL. How 'bout adding another field for ReferenceNumber ? Or you could loop through recordset and use Mid()/Right() to get the RefNumber.
-
Jun 12th, 2008, 07:57 PM
#8
Thread Starter
Hyperactive Member
Re: How to get Max Record
I had tried to use substring and convert method to sperate date function with counter by using subquery. I think the logic can be done but very complicated. I will try to consider to change my reference number to
PC/'date'-seq
the date is follow current date , the seq number will keep counting...
it is the good method ?
or i try ur method to add another new field as counter ..
Thanks Iprank ... L-)
Where there is no hope, there can be no endeavor.
There are two ways of rising in the world, either by your own industry or by the folly of others.
-
Jun 12th, 2008, 08:34 PM
#9
Re: How to get Max Record
-
Jun 12th, 2008, 08:57 PM
#10
Thread Starter
Hyperactive Member
Re: How to get Max Record
Where there is no hope, there can be no endeavor.
There are two ways of rising in the world, either by your own industry or by the folly of others.
-
Jun 12th, 2008, 09:11 PM
#11
Re: How to get Max Record
Here you can do this in Access like:
Code:
SELECT
Right([RefNumbers],Len([RefNumbers])-InStrRev([RefNumbers],"-")) AS OriginalString,
IIf(IsNumeric(OriginalString),CLng(OriginalString),0) AS NumericRefNumber,
*
FROM MyTable
ORDER BY 2 DESC;
Test data:
Code:
RefNumbers
-----------
PC/120608-1
PC/120608-2
PC/190408-1
PC/190408-111
PC/190408-12
PC/190408-22
PC/190408asdd
I don't have SQL 2005 running, But I'm sure it can be done in similar way by using alternate functions: http://www.sql-ref.com/.
-
Jun 12th, 2008, 09:29 PM
#12
Thread Starter
Hyperactive Member
Re: How to get Max Record
Thanks IPrank ,
The way you were provided is useful for me.
Thanks and fully appreciate ...
Where there is no hope, there can be no endeavor.
There are two ways of rising in the world, either by your own industry or by the folly of others.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|