问题
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