July 28, 2010 at 9:28 am
Table has unique identifier column and newid() was inserted into the table.
When select query is executed like below,
select * from table where id = ' d65cafc-1435-45d3-acce-dc464f02c4b1'
error message is displayed.
Error : "Conversion failed when converting from a character string to uniqueidentifier"
Please help
July 28, 2010 at 9:35 am
DECLARE @TABLE AS TABLE(
id UNIQUEIDENTIFIER)
INSERT INTO @TABLE
SELECT Newid()
SELECT *
FROM @TABLE
WHERE CONVERT(VARCHAR(255), id) = 'd65cafc-1435-45d3-acce-dc464f02c4b1'
How's that?
July 28, 2010 at 2:27 pm
Two things.
1. d65cafc-1435-45d3-acce-dc464f02c4b1 is not a proper UNIQUEIDENTIFIER. The first grouping only has 7 characters when there should be 8.
2. Don't rely on implict conversions. CAST the GUID string to a UNIQUEIDENTIFIER and compare it to your column. Don't CAST the column to a string as SQL cannot seek on the index (assuming there is one).
September 18, 2015 at 3:06 am
Ensure that the Column you are Converting OR Casting do not contain BLANK '' Values.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply