环境:sql 2016;
语句 select * from a where pid=joid
上述查询语句中的where pid=joid条件中pid的字段类型为varchar(50)而joid的字段类型为uniqueidentifier,该写法在升级之前的(sql2012)库上没有问题,但在新库(sql2016)中会报错(conversion failed when converting from a character string to uniqueidentifier)。只需对字段(uniqueidentifier)做个类型转换即可(pid=cast(a.joid as varchar(36))),但由于pid字段中存储的数据带“{}”所以需将上述条件改为where substring(pid, 2, len(pid)-2) = cast(joid as varchar(36))