Solved

SQL Statment

Posted on 2011-02-24
6
452 Views
Last Modified: 2012-05-11
i am looking for a sql statment that I run in VBA to get the record from my highest number from a column:
example :
WorkOrderNumber --------------StationID---------------------SequenceNumber
wrk123                                       LAB1                                 1
wrk123                                       LAB2                                 2
wrk123                                       LAB6                                 3

I would like the record from line 3 in my example
here is currently my SQL statment :

strsql = " select STATIONID,TECHID from SVC06100 where WORKORDNUM = '" & StrWORTVNum.Value & "' AND LNITMSEQ is the highest number"


thank you
0
Comment
Question by:taverny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 34975529
try
"select STATIONID,TECHID from SVC06100 A where WORKORDNUM = '" & StrWORTVNum.Value & "'" &
" AND STATIONID = select(stationid, max(LNITMSEQ) from SVC06100 B 
                       where B.stationid = A.stationid group by stationid)"

Open in new window

0
 

Author Comment

by:taverny
ID: 34975578
I am sorry , I am trying to understand the code and I am not sure why we have STATIONID =......

just to be clear i only want the value of STATIONID, TECHID for the LINITMSEQ that has the highest number.
0
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 34975612

Its using a subquery to determine the stationid of the record with the highest LINITMSEQ
The first one has an error, change it to
"select STATIONID,TECHID from SVC06100 A where WORKORDNUM = '" & StrWORTVNum.Value & "' AND STATIONID = (select stationid, max(LNITMSEQ) from SVC06100 B where B.stationid = A.stationid group by stationid)"

Open in new window

0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 52

Accepted Solution

by:
Carl Tawn earned 450 total points
ID: 34975618
Why not just try:
"SELECT TOP 1 StationID, TechID FROM FROM Svc06100 WHERE WorkOrdNum = '" & StrWORTTVNum.Value & "' ORDER BY LNITMSEQ DESC"

Open in new window

0
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 50 total points
ID: 34975621
Sorry, my mistake
"select STATIONID,TECHID from SVC06100 A where WORKORDNUM = '" & StrWORTVNum.Value & "' AND LNITMSEQ = (select  max(LNITMSEQ) from SVC06100 B where B.stationid = A.stationid group by stationid)"

Open in new window

0
 

Author Comment

by:taverny
ID: 34975757
Well, I tried Carl suggestion and it did work perfectly  . Ewangoya, I am still not sure why you want me to group by stationID . But thanks for your help anyway.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question