Saturday, October 27, 2007

SQL Server 2005 Error: Insufficient result space to convert uniqueidentifier value to char.

I was trying to convert a uniqueidentifier column into varchar and stuck up with the "Insufficient result space to convert uniqueidentifier value to char." error message. The cause of the problem is I guess default size of varchar. The uniqueidentifier value which when converted to varchar needs atleast 36 characters which includes 32 characters and 4 dashes.

To come out of the error make sure to specify size of the varchar in convert function. Please see the below code for more details.

declare @var uniqueidentifier
set @var = '1D53379D-C97F-46C2-A22A-0003FA380460'
select convert(varchar(36), @var)
-- select cast(@var as varchar(36))

Thanks!
Dhananjay

No comments: