Pages

Search This Blog

Thursday, August 5, 2010

[T-SQL] ERROR: 8170 Insufficient result space to convert uniqueidentifier value to char

I just came across very simple error and the solution was even simpler. While concatenating NEWID to another varchar string, I had to CONVERT/CAST it to VARCHAR and I accidentally put length of VARCHAR to 10 instead of 36. It displayed following error.

Msg 8170, Level 16, State 2, Line 1
Insufficient result space to convert uniqueidentifier value to char.

The code which I had ran earlier was as following.

SELECT 'GeneratedID:'+CAST(NEWID() AS VARCHAR(10)) AS NEW_ID


Solution:

The solution of above error is extremely simple. I just increased the length from VARCHAR(10) to VARCHAR(36) and it worked fine.

SELECT 'GeneratedID:'+CAST(NEWID() AS VARCHAR(36)) AS NEW_ID

No comments: