<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://rayharwood.com/Wiki/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://rayharwood.com/Wiki/index.php?action=history&amp;feed=atom&amp;title=GUID_fromString_N</id>
		<title>GUID fromString N - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://rayharwood.com/Wiki/index.php?action=history&amp;feed=atom&amp;title=GUID_fromString_N"/>
		<link rel="alternate" type="text/html" href="http://rayharwood.com/Wiki/index.php?title=GUID_fromString_N&amp;action=history"/>
		<updated>2026-11-06T06:27:25Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.20.3</generator>

	<entry>
		<id>http://rayharwood.com/Wiki/index.php?title=GUID_fromString_N&amp;diff=47&amp;oldid=prev</id>
		<title>Rayharwood at 18:50, 22 October 2013</title>
		<link rel="alternate" type="text/html" href="http://rayharwood.com/Wiki/index.php?title=GUID_fromString_N&amp;diff=47&amp;oldid=prev"/>
				<updated>2013-10-22T18:50:20Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
			&lt;tr style='vertical-align: top;'&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
			&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 18:50, 22 October 2013&lt;/td&gt;
			&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 37:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 37:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Then, when doing an insert, use the function in a manner similar to this:&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;Then, when doing an insert, use the function in a manner similar to this:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;#160; INSERT INTO [MyDatabase].[dbo].[DestinationTable]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;  ([GoodGUID]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;  ,[OtherInfo])&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;#160; select &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;  [MyDatabase].dbo.GUID_fromString_N(S.[StringKeyField])&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;  ,'Oh yeah, we did it!'&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt;&amp;#160;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;color: red; font-weight: bold; text-decoration: none;&quot;&gt;&amp;#160; FROM [MyDatabase].[dbo].[SourceTable]&amp;#160; S&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Rayharwood</name></author>	</entry>

	<entry>
		<id>http://rayharwood.com/Wiki/index.php?title=GUID_fromString_N&amp;diff=46&amp;oldid=prev</id>
		<title>Rayharwood: Created page with &quot;There are several formats acceptable for GUIDs, but SQL only accepts &quot;D-Format&quot; GUIDs when inserting into the database.  If you have a 32 character hex string (an &quot;N-Format&quot; G...&quot;</title>
		<link rel="alternate" type="text/html" href="http://rayharwood.com/Wiki/index.php?title=GUID_fromString_N&amp;diff=46&amp;oldid=prev"/>
				<updated>2013-10-22T18:45:07Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;There are several formats acceptable for GUIDs, but SQL only accepts &amp;quot;D-Format&amp;quot; GUIDs when inserting into the database.  If you have a 32 character hex string (an &amp;quot;N-Format&amp;quot; G...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;There are several formats acceptable for GUIDs, but SQL only accepts &amp;quot;D-Format&amp;quot; GUIDs when inserting into the database.&lt;br /&gt;
&lt;br /&gt;
If you have a 32 character hex string (an &amp;quot;N-Format&amp;quot; GUID) and need to insert it into a UniqueIdentifer column, here's a function you can create:&lt;br /&gt;
&lt;br /&gt;
  USE [MyDatabase]&lt;br /&gt;
  GO&lt;br /&gt;
  SET ANSI_NULLS ON&lt;br /&gt;
  GO&lt;br /&gt;
  SET QUOTED_IDENTIFIER ON&lt;br /&gt;
  GO&lt;br /&gt;
  -- =============================================&lt;br /&gt;
  -- Author:	Ray Harwood&lt;br /&gt;
  -- Create date: 10/22/2013&lt;br /&gt;
  -- Description:	Takes N-formatted GUID string (32 hex characters) and creates D-Formatted GUID&lt;br /&gt;
  -- See http://msdn.microsoft.com/en-us/library/97af8hh4.aspx&lt;br /&gt;
  -- Also http://stackoverflow.com/questions/1390109/convert-varchar-to-uniqueidentifier-in-sql-server&lt;br /&gt;
  -- =============================================&lt;br /&gt;
  CREATE FUNCTION [dbo].[GUID_fromString_N]&lt;br /&gt;
  (&lt;br /&gt;
  	-- Add the parameters for the function here&lt;br /&gt;
  	@GString varchar(50)&lt;br /&gt;
  )&lt;br /&gt;
  RETURNS uniqueidentifier&lt;br /&gt;
  AS&lt;br /&gt;
  BEGIN&lt;br /&gt;
  	-- Declare the return variable here&lt;br /&gt;
  	DECLARE @GUID uniqueidentifier&lt;br /&gt;
  	-- Add the T-SQL statements to compute the return value here&lt;br /&gt;
  	SELECT @GUID = CAST(&lt;br /&gt;
          SUBSTRING(@GString, 1, 8) + '-' + SUBSTRING(@GString, 9, 4) + '-' + SUBSTRING(@GString, 13, 4) + '-' +&lt;br /&gt;
          SUBSTRING(@GString, 17, 4) + '-' + SUBSTRING(@GString, 21, 12)&lt;br /&gt;
          AS UNIQUEIDENTIFIER)&lt;br /&gt;
  	-- Return the result of the function&lt;br /&gt;
  	RETURN @GUID&lt;br /&gt;
  END&lt;br /&gt;
  GO&lt;br /&gt;
&lt;br /&gt;
Then, when doing an insert, use the function in a manner similar to this:&lt;/div&gt;</summary>
		<author><name>Rayharwood</name></author>	</entry>

	</feed>