I am currently tasked with converting a bunch of C# CRL code into SQL stored procedures and scalar functions. The task seems enough simple at first glance, until I stumbled upon a piece of code that generates a new Guid with a byte array as parameter. The code looks like this:
public static Guid GenerateGuid()
{
var bytes = GenerateBytes();
return new Guid(bytes);
}
The bytes generated is not the concern here, what puzzles me is how C# uses this byte array to create a new Guid instance. In SQL server, however, there is only one function NEWID() which accepts no parameter, it is similar to Guid.NewGuid(). Unfortunately it is not what I need for this use case.
So I’d like to ask there a way I can rewrite the above C# code into SQL to generate a new Guid with specified byte array instead of just a completely random Guid using NEWID()?