MSSQL CFUUID Function
Michael Sharman over at the Chapter 31 blog has a nice post on working with ColdFusion UUID's and MSSQL. One of his functions to create a uuid uses the newid() function twice to generate a ColdFusion compatible UUID. While it may work, each call to the newid() generates a new ms uuid. I had created a similar function for Oracle awhile back so I whipped up a quick MSSQL user defined function to provide the same result.
The below custom function, which uses the same string concat function from Michael's blog entry is a little cleaner in that it only creates one ms uuid and then creates the cf uuid from that.
The Function
CREATE FUNCTION dbo.cfuuid(@msID varchar(36))
RETURNS varchar(35)
AS
BEGIN
DECLARE @myCFID varchar(35)
SET @myCFID = left(@msID, 23) + right(@msID,12)
RETURN @MyCFID
END
To call it;
select dbo.cfuuid(newid()) as myid

