Solved

SQL Statment

Posted on 2011-02-24
6
447 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
  • 3
  • 2
6 Comments
 
LVL 32

Expert Comment

by:ewangoya
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:ewangoya
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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:ewangoya
ewangoya 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now