Skip to main content

As described in Unique values | USoft Community one can refer to a last generated unique value from the rules engine. Would there be a (n undocumented maybe) feature available that enables specifying that for its transaction or even relate that to the table that it was used for?

Jan,

The RulesEngine.GetLastGeneratedUniqueValue() returns the latest value generated in your transaction. If you call the method directly after inserting a record, it will return the value you want to know.

For tables with a single column primary key based on a domain that generates unique values, you could search for the latest value used with a function executing the SQL below:
    

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- Description: function to retrieve current value of a sequence object used as primary key value for a given table

CREATE FUNCTION get_current_sequence_number
(
-- Add the parameters for the function here
@tableName sysname
)
RETURNS int
AS
BEGIN
-- Declare the return variable here
declare
@currval int;

-- Add the T-SQL statements to compute the return value here
SELECT @currval = CAST( seq.current_value as int )
FROM sys.sequences as "seq"
WHERE
seq.name = 'SEQ_' + @tableName;

-- Return the result of the function
RETURN @currval

END
GO


Regards,

Robert


Reply