开发者

Argument data type uniqueidentifier is invalid for argument 1 of substring function

开发者 https://www.devze.com 2022-12-18 09:33 出处:网络
I 开发者_开发技巧am trying to get the first part of a Guid Field with the TSQL substring function as follows

I 开发者_开发技巧am trying to get the first part of a Guid Field with the TSQL substring function as follows

SELECT SUBSTRING(Guid, 1, 8) AS Gu FROM MyTable

but all i get is this error.

Argument data type uniqueidentifier is invalid for argument 1 of substring function.

So what is going on here? Should i treat the Guid as pure string first or...?

Thanks in advance!


Try this:

SELECT SUBSTRING(CAST(Guid AS varchar(38)), 1, 8) AS Gu FROM MyTable

You can't perform SUBSTRING directly on a uniqueidentifier; you need to cast it to a string type (varchar) first.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号