Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Statment

Posted on 2011-02-24
6
Medium Priority
?
456 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: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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 52

Accepted Solution

by:
Carl Tawn earned 1800 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 200 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 Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
In this article I will describe the Backup & Restore 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.
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…
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…

773 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