Using MAX in SELECT Criteria

  • Trying to create a stored proc that just returns an ID column and not the date column I need for the criteria.

    tblLASER_CHAR stores system characterizations. Each system may have multiple characterizations. Systems are uniquely identified by both SYSTEM_SN and SYSTEM_WO. Given the SN and WO of a system I want the most recent characterization.

    The following is wrong but kind of represents what I want to get:

    CREATE PROCEDURE [dbo].[sp_GET_LASER_CHAR_ID]

    @SYS_SN [char](10),

    @SYS_WO [char](10)

    AS

    SELECT LASER_CHAR_ID

    FROM dbo.tblLASER_CHAR

    WHERE (SYSTEM_SN = @SYS_SN) AND (SYSTEM_WO = @SYS_WO) AND (STATUS = 'CLOSED ')

    GROUP BY LASER_CHAR_ID

    HAVING MAX(CREATE_DATE)


    Kindest Regards,

    Sean Wyatt
    seanwyatt.com

  • many different ways of doing this...

    try

    select top 1 columnname from tablename where ... order by ...

     

  • Thanks,

    I knew I was overlooking something simple.


    Kindest Regards,

    Sean Wyatt
    seanwyatt.com

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply