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

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/11327.html
標籤:SQL Server
