venerdì 3 gennaio 2014

SQL: Retrive a new RECID for insert direct on Dynamics Ax table

DECLARE @TABLENAME nvarchar(40)
DECLARE @TABLEID int

SET @TABLENAME = 'TABLENAME'

IF (@TABLENAME = '')
BEGIN
RAISERROR ('Il parametro @TABLENAME deve essere specificato', 16, 1);
RETURN
END

SELECT @TABLEID = TABLEID FROM SQLDICTIONARY WHERE NAME = @TABLENAME AND FIELDID = 0
IF (ISNULL(@TABLEID, 0) = 0)
BEGIN
RAISERROR ('The table %1.40s does not exists', 16, 1, @TABLENAME);
RETURN
END

BEGIN TRANSACTION
DECLARE @RECID bigint = (SELECT NEXTVAL FROM SYSTEMSEQUENCES WHERE TABID = @TABLEID AND NAME = 'SEQNO')
IF (ISNULL(@RECID, 0) = 0)
BEGIN
RAISERROR ('Unable to get new RECID for the table  %1.40s', 16, 1, @TABLENAME);
RETURN
END

UPDATE SYSTEMSEQUENCES SET NEXTVAL = @RECID + 1 WHERE TABID = @TABLEID AND NAME = 'SEQNO'
COMMIT TRANSACTION


SELECT @RECID

Nessun commento:

Posta un commento

AX 2012: The request was aborted: Could not create SSL/TLS secure channel

The error you're encountering, "The request was aborted: Could not create SSL/TLS secure channel," can occur due to various re...