Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Statment

Posted on 2011-02-24
6
Medium Priority
?
454 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
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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 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…

715 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