环境: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))