MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old March 11th, 2004, 09:27 PM
winterain4u winterain4u is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Kuala Lumpur
Posts: 81 winterain4u User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 54 m
Reputation Power: 5
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.

Reply With Quote
  #2  
Old March 20th, 2004, 04:09 PM
sypher sypher is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Montreal
Posts: 92 sypher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 10 sec
Reputation Power: 5
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Select Max


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway