sql server - Increment a uniqueidentifier in TSQL -


I am looking for a way to increase a unique identifier by 1 in TSQL. For example, if the ID is A6BC60AD-A4D9-46F4-A7D3-98B2A7237A9E, I would like to be able to select the A6BC60AD-A4D9-46F4-A7D3-98B2A7237A9F.

@rein This is for a data import. We have an intermediate table in which the IDs have been entered, and we are later included in the import at these IDs. Unfortunately, some of these records now produce some records in the next table, so we need a new ID that is reproducible.

The way you want to increase, the GUI is not right for SQL Server because the Git byte group There is a structure with different byte orders, please see this: and notice the following:

Now, when I run a revised Alberto query, I get the following sequence: 3, 2, 1, 0, 5, 4, 7, 6, 9, 8, 15, 14, 13, 12, 11, 10

This means that by GUID the byte is less than # 3 Less important and GUID Byte # 10 is the most important [in the Clause perspective by the SQL Server command]

Here is the simple task for increasing accounting for a uniqueidentifier.

  Function [dbo] [IncrementGuid] (@ GUID uniqueidentifier) ​​Creating Uniqueidentifier returns announced as the @guid_binary binary (16), @ B03 binary (4), @ b 45 binary (2), @ b67 binary (2), @ b89 binary mango (2), @bAF binary (6) selection @guid_binary = @guid selection @ B03 = convert (binary (4), reverse (substring ( @ Guid_binary, 1,4)) Select @ B45 = Convert (binary (2), reverse (substrings (@ guid_binary, 5,2)), select @ b67 = convert (binary (2), reverse (substring ( @ Guid_binary, 7,2))) @ b89 = Convert (binary (2), substring (@guid_binary, 9, 2)) @ BAF = Convert (binary (6), substring (@guide_binary, 11,6) select (@ b03 & lt; 'FFFFFFFF') = start selectively @ B03 changed (binary (4), Dali (integer as @ B03) +1) End else if (@ B45 & lt; 'FFFF') = Start Choice Selected @ B45 (Binary (2), Dali (@ B45 as integer) + 1) Any And end if (@ b89 & lt; 'FFFF') start selectively @ b89 = convert (binary (2), cast (@ b89 as integer) +1) end select @bAF start = (binary (6 ), Cast (@ BAF Bilint) Reverse (convert (four (4), @ b3) reverse (convert (four (2) convert (four (6), @ baaf)) end  
convert (four (2), @ B8 9) + reverse (convert (four (2), b @ 67)

Note that byte 6 and 7 did not increase because they were grid version bits Include. But as the others have told you that should not really should do this in your case it may be better if you create a temporary table for these goods (with two columns: An integer in the form of index and the second one with generated goods).


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -