Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 356949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:09:35+00:00 2026-05-12T12:09:35+00:00

A table I have no control of the schema for, contains a column defined

  • 0

A table I have no control of the schema for, contains a column defined as varchar(50) which stores uniqueidentifiers in the format ‘a89b1acd95016ae6b9c8aabb07da2010’ (no hyphens)

I want to convert these to uniqueidentifiers in SQL for passing to a .Net GUID. However, the following query lines don’t work for me:

select cast('a89b1acd95016ae6b9c8aabb07da2010' as uniqueidentifier)
select convert(uniqueidentifier, 'a89b1acd95016ae6b9c8aabb07da2010')

and result in:

Msg 8169, Level 16, State 2, Line 1
Conversion failed when converting from a character string to uniqueidentifier.

The same queries using a hyphenated uniqueidentifier work fine but the data is not stored in that format.

Is there another (efficient) way to convert these strings to uniqueidentifiers in SQL. — I don’t want to do it in the .Net code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T12:09:35+00:00Added an answer on May 12, 2026 at 12:09 pm
    DECLARE @uuid VARCHAR(50)
    SET @uuid = 'a89b1acd95016ae6b9c8aabb07da2010'
    SELECT  CAST(
            SUBSTRING(@uuid, 1, 8) + '-' + SUBSTRING(@uuid, 9, 4) + '-' + SUBSTRING(@uuid, 13, 4) + '-' +
            SUBSTRING(@uuid, 17, 4) + '-' + SUBSTRING(@uuid, 21, 12)
            AS UNIQUEIDENTIFIER)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have no control over database schema and have the following (simplified) table structure:
I have an unbound XtraReport that has a subreport control which contains another report.
I have no control over how the data is saved in this table. However,
Hopefully I am overlooking a something simple. I have tablix control with a table
Okay, I'm stumped here. I have a control that is comprised of a table.
I have a table with below structure. I am not having control over changing
I have a table schema similar to the following (simplified): CREATE TABLE Transactions (
I have a question about User-Defined Table Types in SQL Server 2008. For the
I want to have folders and documents which every one have a folder. Folders
I have XML data type as a table column. I have stored some XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.