locked
Conversion failed when converting from a character string to uniqueidentifier RRS feed

  • Question

  • how to convert the charter string to uniqueidentifier in  sql server 

    I tried for all the articals in the net can some one give me the better soluction for this.. i will use the cast and convert function but i didnt get the soluction over here.

    can you please give me the answer for this query........

    i have table called user1 contains column col1,

    col1

    d65cafc-1435-45d3-acce-dc464f02c4b1

    Wednesday, October 22, 2014 11:54 AM

Answers

  • The first part is to short, it must be 8 signs, you have only 7; I added a zero and it works =>

    DECLARE @id varchar(60);
    SET @id = 'd65cafc0-1435-45d3-acce-dc464f02c4b1'
    
    SELECT CONVERT(uniqueidentifier, @id)


    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    • Marked as answer by Kalman Toth Monday, November 17, 2014 5:21 PM
    Wednesday, October 22, 2014 12:03 PM
    Answerer

All replies

  • The first part is to short, it must be 8 signs, you have only 7; I added a zero and it works =>

    DECLARE @id varchar(60);
    SET @id = 'd65cafc0-1435-45d3-acce-dc464f02c4b1'
    
    SELECT CONVERT(uniqueidentifier, @id)


    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    • Marked as answer by Kalman Toth Monday, November 17, 2014 5:21 PM
    Wednesday, October 22, 2014 12:03 PM
    Answerer
  • Hi saz,

    here  i have a set of id's are there in the table , i want to select all the values and convert into  to the uniqueidentifier

    Thanks!

    Wednesday, October 22, 2014 1:49 PM