Solved

SQL Statment

Posted on 2011-02-24
6
448 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
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: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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

910 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

21 Experts available now in Live!

Get 1:1 Help Now