Files
GMW/GMW_DB/dmtx/Stored Procedures/stp_getFirstLastDtx.sql
Samuele Locatelli e7da820ab0 pulizia codice SQL x maiuscole/minuscole
fix webconfig 218_test
2014-05-20 08:19:05 +02:00

51 lines
1.2 KiB
Transact-SQL

/*************************************************
* STORED stp_getFirstLastDtx
*
* fornisce primo-ultimo DataMatrix della posizione/cella indicata
*
* Steamware, S.E.L.
* mod: 2014.03.12
*
*************************************************/
CREATE PROCEDURE [dmtx].[stp_getFirstLastDtx]
(
@CodCella NVARCHAR(50)
)
AS
DECLARE @DtxStart NVARCHAR(50),
@DtxEnd NVARCHAR(50)
-- recupero primo DataMatrix
SELECT TOP 1 @DtxStart = d2c.DataMatrix
FROM dmtx.v_ElencoDatamatrixBMW edb
INNER JOIN dbo.Dtx2UDC d2c
ON edb.DataMatrix = d2c.DataMatrix COLLATE Latin1_General_CI_AS
INNER JOIN dbo.PosizioneUdcCorrente puc
ON d2c.UDC = puc.UDC
INNER JOIN Celle c
ON puc.IdxCella = c.IdxCella
WHERE c.CodCella = @CodCella
AND edb.EsitoMarcatura = 'OK'
ORDER BY edb.DataOra
-- recupero ultimo DataMatrix
SELECT TOP 1 @DtxEnd = d2c.DataMatrix
FROM dmtx.v_ElencoDatamatrixBMW edb
INNER JOIN dbo.Dtx2UDC d2c
ON edb.DataMatrix = d2c.DataMatrix COLLATE Latin1_General_CI_AS
INNER JOIN dbo.PosizioneUdcCorrente puc
ON d2c.UDC = puc.UDC
INNER JOIN Celle c
ON puc.IdxCella = c.IdxCella
WHERE c.CodCella = @CodCella
AND edb.EsitoMarcatura = 'OK'
ORDER BY edb.DataOra DESC
-- restituisco output
SELECT @DtxStart AS DtxStart, @DtxEnd AS DtxEnd
RETURN