{"id":67,"date":"2008-01-29T11:26:28","date_gmt":"2008-01-29T15:26:28","guid":{"rendered":"http:\/\/ryepup.unwashedmeme.com\/blog\/2008\/01\/29\/sql-server-2005-doesnt-like-bitwise-comparison-of-large-numbers\/"},"modified":"2008-01-29T11:26:28","modified_gmt":"2008-01-29T15:26:28","slug":"sql-server-2005-doesnt-like-bitwise-comparison-of-large-numbers","status":"publish","type":"post","link":"http:\/\/ryepup.unwashedmeme.com\/blog\/2008\/01\/29\/sql-server-2005-doesnt-like-bitwise-comparison-of-large-numbers\/","title":{"rendered":"SQL Server 2005 doesn&#8217;t like bitwise comparison of large numbers"},"content":{"rendered":"<p>An update trigger using COLUMNS_UPDATED() was failing, and I figured out the problem:<\/p>\n<p>Some simple SQL:<\/p>\n<p>SELECT CAST(0x0200 as bigint), 0x0200 | 0<br \/>\nSELECT CAST(0x02000 as bigint), 0x02000 | 0<br \/>\nSELECT CAST(0x020000 as bigint), 0x020000 | 0<br \/>\nSELECT CAST(0x0200000 as bigint), 0x0200000 | 0<br \/>\nSELECT CAST(0x02000000 as bigint), 0x02000000 | 0<br \/>\nSELECT CAST(0x020000000 as bigint), 0x020000000 | 0<br \/>\nSELECT CAST(0x0200000000 as bigint), 0x0200000000 | 0<br \/>\nI had &#8220;IF COLUMNS_UPDATED() | 0 &gt; 0&#8221; in my trigger, and on large values of COLUMNS_UPDATED(), bitwise ORing with zero equals zero.\u00c2\u00a0 Of course, &#8220;IF COLUMNS_UPDATED() | 0 &gt; 0&#8221; is a retarded way to say &#8220;IF COLUMNS_UPDATED() &gt; 0&#8221;, but whatever codepath that large number triggers wigs out there to.\u00c2\u00a0 Try these out:<\/p>\n<p>SELECT 1 WHERE 0x0200000000 &gt; 0<br \/>\nSELECT 1 WHERE CAST(0x0200000000 as bigint) &gt; 0<\/p>\n<p>So, to fix my trigger, I have &#8220;IF CAST(COLUMNS_UPDATED() as bigint) &gt; 0&#8221;, which still seems a little retarded, but at least my trigger works.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An update trigger using COLUMNS_UPDATED() was failing, and I figured out the problem: Some simple SQL: SELECT CAST(0x0200 as bigint), 0x0200 | 0 SELECT CAST(0x02000 as bigint), 0x02000 | 0 SELECT CAST(0x020000 as bigint), 0x020000 | 0 SELECT CAST(0x0200000 as bigint), 0x0200000 | 0 SELECT CAST(0x02000000 as bigint), 0x02000000 | 0 SELECT CAST(0x020000000 as bigint), [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,20,6],"tags":[],"class_list":["post-67","post","type-post","status-publish","format-standard","hentry","category-annoying","category-mssql","category-windows"],"_links":{"self":[{"href":"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-json\/wp\/v2\/posts\/67","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-json\/wp\/v2\/comments?post=67"}],"version-history":[{"count":0,"href":"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-json\/wp\/v2\/posts\/67\/revisions"}],"wp:attachment":[{"href":"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-json\/wp\/v2\/media?parent=67"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-json\/wp\/v2\/categories?post=67"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ryepup.unwashedmeme.com\/blog\/wp-json\/wp\/v2\/tags?post=67"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}