· 7 years ago · Oct 30, 2018, 01:20 PM
1drop table if exists MyGuidTestTable;
2create table MyGuidTestTable (Id int identity,Guid1 uniqueidentifier null, Guid2 uniqueidentifier null,OtherColumn nvarchar(100));
3
4DECLARE @i int = 0
5WHILE @i < 3000
6BEGIN
7 SET @i = @i + 1;
8 insert into MyGuidTestTable (Guid1,Guid2,OtherColumn) values (NEWID(),null,case when @i%2=0 then 'not null string' else null end);
9END
10
11--Query I wrote
12select * from MyGuidTestTable
13where Guid1<>isnull(Guid2,newid())
14
15--Query SqlServer is executing
16select * from MyGuidTestTable
17where Guid1>isnull(Guid2,newid()) or Guid1<isnull(Guid2,newid())
18
19SELECT rh.HashedData
20 ,rh.InternalIdentifyingData
21 ,rh.LastSyncedHash
22 ,CASE
23 WHEN rh.LastSyncedHash IS NULL
24 THEN 1
25 ELSE LastScanStatus
26 END 'LastScanStatus'
27 ,rh.Id 'HashMappingID'
28FROM sync.RecordsHashes rh
29INNER JOIN Sync.Attributes_Translations tbl ON tbl.Id = rh.RecordId
30 AND rh.RecordType = N'Attributes_Translations'
31WHERE rh.LastScanStatus != 3 --deleted=3
32 AND rh.HashedData <> isnull(rh.LastSyncedHash, NEWID())
33 AND (
34 rh.LastSynce