USE ERPLITE_SIT
DECLARE @MaxRecID BIGINT
DECLARE @NextVal BIGINT
SELECT @MaxRecID = MAX(RECID)
FROM PURCHTABLE
SELECT @NextVal = NEXTVAL
FROM SYSTEMSEQUENCES
INNER JOIN SQLDICTIONARY
ON SQLDICTIONARY.FIELDID = 0
AND SQLDICTIONARY.name = 'PURCHTABLE'
AND SQLDICTIONARY.TABLEID = SYSTEMSEQUENCES.TABID
IF (@NextVal > @MaxRecID)
BEGIN
PRINT 'PURCHTABLE did not need to be updated.'
END
ELSE
BEGIN
PRINT 'Updated PURCHTABLE from ' + CONVERT(VARCHAR(MAX), @NextVal) + '' + 'to' + '' + CONVERT(VARCHAR(MAX), @MaxRecID + 1)
UPDATE SYSTEMSEQUENCES
SET NEXTVAL = @MaxRecID + 1
FROM SYSTEMSEQUENCES
INNER JOIN SQLDICTIONARY
ON SQLDICTIONARY.FIELDID = 0
AND SQLDICTIONARY.name = 'PURCHTABLE'
AND SQLDICTIONARY.TABLEID = SYSTEMSEQUENCES.TABID
END
DECLARE @MaxRecID BIGINT
DECLARE @NextVal BIGINT
SELECT @MaxRecID = MAX(RECID)
FROM PURCHTABLE
SELECT @NextVal = NEXTVAL
FROM SYSTEMSEQUENCES
INNER JOIN SQLDICTIONARY
ON SQLDICTIONARY.FIELDID = 0
AND SQLDICTIONARY.name = 'PURCHTABLE'
AND SQLDICTIONARY.TABLEID = SYSTEMSEQUENCES.TABID
IF (@NextVal > @MaxRecID)
BEGIN
PRINT 'PURCHTABLE did not need to be updated.'
END
ELSE
BEGIN
PRINT 'Updated PURCHTABLE from ' + CONVERT(VARCHAR(MAX), @NextVal) + '' + 'to' + '' + CONVERT(VARCHAR(MAX), @MaxRecID + 1)
UPDATE SYSTEMSEQUENCES
SET NEXTVAL = @MaxRecID + 1
FROM SYSTEMSEQUENCES
INNER JOIN SQLDICTIONARY
ON SQLDICTIONARY.FIELDID = 0
AND SQLDICTIONARY.name = 'PURCHTABLE'
AND SQLDICTIONARY.TABLEID = SYSTEMSEQUENCES.TABID
END
No comments:
Post a Comment