Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) Generate Monotonic ULIDsSee more ULID/UUID ExamplesGenerate a sequence of monotonic ULIDs all using the same seed time. This code sample generates a series of ULIDs with continuously increasing values. Important: Chilkat's ULID functionality was introduced in v9.5.0.94.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) DECLARE @seedDt int -- Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.CkDateTime', @seedDt OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- You can set the seed time to any desired value. -- In this example, the seed time is set to the current system date/time. DECLARE @success int EXEC sp_OAMethod @seedDt, 'SetFromCurrentSystemTime', @success OUT -- Generate the 1st ULID in the series. -- (i.e. the current UTC UNIX-time) DECLARE @utc int SELECT @utc = 1 DECLARE @ulid nvarchar(4000) EXEC sp_OAMethod @seedDt, 'UlidGenerate', @ulid OUT, @utc PRINT @ulid -- Store the ULID in a Chilkat StringBuilder to generate the series. DECLARE @sbUlid int -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbUlid OUT EXEC sp_OAMethod @sbUlid, 'Append', @success OUT, @ulid DECLARE @i int SELECT @i = 0 WHILE @i < 50 BEGIN EXEC sp_OAMethod @seedDt, 'UlidIncrement', @success OUT, @sbUlid EXEC sp_OAMethod @sbUlid, 'GetAsString', @sTm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