Compare uniqueidentifier in where clause

倖福魔咒の 提交于 2019-12-11 09:27:20

问题


We have two tables : MainTable and CloneOfMainTable

The structure of both tables is :

ID : int Identity Primarykey
Foo: nvarchar(50) 
RowVersion : uniqueidentifier

We want to simply get the updated rows by comparing RowVersion and bla bla ...

SELECT * 
FROM MainTable 
INNER JOIN CloneOfMainTable On MainTable.ID = CloneOfMainTable.ID
WHERE MainTable.RowVersion <> CloneOfMainTable.RowVersion

and it doesn't work ^_^"


回答1:


There are no limitations on comparing uniqueidentifier values. As the column is nullable you may use coalesce to include null values in comparison:

WHERE coalesce(MainTable.RowVersion,'00000000-0000-0000-0000-000000000000') <> coalesce(CloneOfMainTable.RowVersion,'00000000-0000-0000-0000-000000000000')


来源:https://stackoverflow.com/questions/29731416/compare-uniqueidentifier-in-where-clause

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!