|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
Select Max
Can anyone help me in this problem?
At table do_master, there are a field "do_no", the data is like : D0400001 D0400003 D0400004 D0400005 D0400006 String sqldono = "SELECT convert(int,(SUBSTRING(do_no,4,8))) AS do1 FROM do_master WHERE (SUBSTRING(do_no,1,3))='D04' ORDER BY do_no"; The result is 00001 00003 00004 00005 00006 I would like to get the max, that is 00006. String sqldono = "SELECT MAX(convert(int,(SUBSTRING(do_no,4,8)))) AS do1 FROM do_master WHERE (SUBSTRING(do_no,1,3))='D04' ORDER BY do_no"; It is not work.. Any error for sqldono above? Thanks~~
__________________
winterain Last edited by winterain4u : March 11th, 2004 at 09:30 PM. |
|
#2
|
|||
|
|||
|
try this:
SELECT SUBSTRING(do_no,4,8) FROM do_master WHERE (SUBSTRING(do_no,1,3))='D04' AND convert(int,(SUBSTRING(do_no,4,8)))= (SELECT MAX(convert(int,(SUBSTRING(do_no,4,8)))) AS do1 FROM do_master WHERE (SUBSTRING(do_no,1,3))='D04') Basicaly I did a subquery(the second select) to get the Max of do_no then I compare the table to get the record with has a 6 for the expression convert(int,(SUBSTRING(do_no,4,8))) Ouput ----- 0006 Last edited by sypher : March 20th, 2004 at 04:18 PM. |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Select Max |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|