Solved

nchar(36) value causing conversion failure when attempting to update to a uniqueidentifier column

Posted on 2008-10-08
2
427 Views
Last Modified: 2012-06-27
I have a database with over 40 tables.  The PK's and FK's were originally defined as nchar(35) to be compatible with the GUID format of ColdFusion.  The middleware for the project has now been changed to .NET and the data architect wishes the nchar(35)'s to be converted over to uniqueidentifier columns in SQL Server.  These tables are currently filled with data.

I have been working on this project and am nearly complete with the TSQL Script to convert the entire database, but have run into a very strange situation.

An nchar(35) ColdFusion GUID looks like this:
05439AB0-2881-4DE7-AD40-FFF680F07225

A SQL Server UNIQUEIDENTIFIER looks like this:
05439ab0-2881-4de7-ad40-fff680f07225

Note the only difference is the hyhen at position 19.  Additionally, the uniqueidentifier uses lower case, not upper case.  The length of the former is 35, the length of the latter is 36.

To make a long story short, in order to affect the conversion, after dropping all the FK and PK constraints, I follow these steps:

* modify the column containing the GUID from nchar(35) to nchar(36)
* update each value to insert the additional hyphen at position 19
* rename the column to nameID_OLD
* add a new column to the table named ID of type uniqueidentifier
* run an update command to update the ID column with the values in the nameID_OLD column.

My problem is that I have come across a value that is causing SQL Server to report a "Conversion failed when converting from a character string to uniqueidentifier." error as I am running the following command:

update tblTest
set manufacturerID = lower(manufacturerID_OLD)

-- NOTE:
--manufacturerID is of datatype uniqueidentier
--manufacturerID_OLD is of datatype nchar(36)

Nearly all values will convert implicitly to the uniqueidentifier perfectly.  However this value: df0351fa-34f8-49b0-b630-f1294324398t will reliably throw the conversion failure error.

Is there something about this value that causes SQL Server to see this as an invalid uniqueidentifier?  What is the spec behind a uniqueidentifier such that I might write a regular expression to locate incorrectly formatted uniqueidentifiers?





0
Comment
Question by:szabogi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

Accepted Solution

by:
QPR earned 500 total points
ID: 22674803
is the t on the end a typo?
If this is hex then shouldn't F be the highest value allowed?
0
 
LVL 1

Author Closing Comment

by:szabogi
ID: 31504507
Yes, that's it precisely.  I needed another set of eyes on this.  Thanks very much for your speedy response.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question