Sample Max off in SQL :
SELECT DISTINCT INVENTJOURNALTABLE.JOURNALID+INVENTDIM.INVENTLOCATIONID AS STInternalTransferInID,
Dateadd(hour, 7, INVENTJOURNALTABLE.POSTEDDATETIME) as ITNDate,
Dateadd(hour, 7, (SELECT MAX(INVENTJOURNALTRANS.TRANSDATE)
from INVENTJOURNALTRANS where INVENTJOURNALTRANS.JOURNALID = inventjournalTable.JOURNALID)) as Transdate,
INVENTJOURNALTABLE.INVENTLOCATIONID As SendersLocationID,
INVENTDIM.INVENTLOCATIONID AS EstateID,
INVENTJOURNALTABLE.POSTED,
INVENTJOURNALTABLE.DESCRIPTION AS Remarks,
INVENTJOURNALTABLE.CREATEDBY,
INVENTJOURNALTABLE.MODIFIEDBY,
Dateadd(hour, 7, INVENTJOURNALTABLE.MODIFIEDDATETIME) as ModifiedOn,
Dateadd(hour, 7, INVENTJOURNALTABLE.POSTEDDATETIME) as CreateOn,
INVENTJOURNALTABLE.DATAAREAID
FROM INVENTJOURNALTABLE
inner join INVENTJOURNALTRANS ON INVENTJOURNALTABLE.JOURNALID = INVENTJOURNALTRANS.JOURNALID
inner join inventdim on inventdim.INVENTDIMID = INVENTJOURNALTRANS.TOINVENTDIMID
WHERE (INVENTJOURNALTABLE.DATAAREAID = 'BSP') AND (INVENTJOURNALTABLE.JOURNALTYPE = 2) AND INVENTJOURNALTABLE.BIT_TransferToIplant = '1'
SELECT DISTINCT INVENTJOURNALTABLE.JOURNALID+INVENTDIM.INVENTLOCATIONID AS STInternalTransferInID,
Dateadd(hour, 7, INVENTJOURNALTABLE.POSTEDDATETIME) as ITNDate,
Dateadd(hour, 7, (SELECT MAX(INVENTJOURNALTRANS.TRANSDATE)
from INVENTJOURNALTRANS where INVENTJOURNALTRANS.JOURNALID = inventjournalTable.JOURNALID)) as Transdate,
INVENTJOURNALTABLE.INVENTLOCATIONID As SendersLocationID,
INVENTDIM.INVENTLOCATIONID AS EstateID,
INVENTJOURNALTABLE.POSTED,
INVENTJOURNALTABLE.DESCRIPTION AS Remarks,
INVENTJOURNALTABLE.CREATEDBY,
INVENTJOURNALTABLE.MODIFIEDBY,
Dateadd(hour, 7, INVENTJOURNALTABLE.MODIFIEDDATETIME) as ModifiedOn,
Dateadd(hour, 7, INVENTJOURNALTABLE.POSTEDDATETIME) as CreateOn,
INVENTJOURNALTABLE.DATAAREAID
FROM INVENTJOURNALTABLE
inner join INVENTJOURNALTRANS ON INVENTJOURNALTABLE.JOURNALID = INVENTJOURNALTRANS.JOURNALID
inner join inventdim on inventdim.INVENTDIMID = INVENTJOURNALTRANS.TOINVENTDIMID
WHERE (INVENTJOURNALTABLE.DATAAREAID = 'BSP') AND (INVENTJOURNALTABLE.JOURNALTYPE = 2) AND INVENTJOURNALTABLE.BIT_TransferToIplant = '1'
0 comments:
Post a Comment