
as halloween descends upon us, mysterious emails start reaching our inbox. these plaintive missives are but the screams of the damned, encoded and sent over smtp. 




for example, someone known to us only as dba guy sent an email with this subject: <u+201c>silver bullet sql scalar function built by the ancient ones<u+201d>. 




these ancient ones obviously did not come from the euclidian plane we know so well, but obviously from a twisted, higher dimensional space where there exist no right angles. 




the code itself, is simple: /* name fnvaluechanged purpose: returns a value based on the parameters passed in which will tell the user whether or not 2 values have changed usage select dbo.fnvaluechanged(parameter1,parameter2,parameter3,parametern...) returns tinyint */ alter function [dbo].[fnvaluehaschanged] ( @poldvalue varchar(255), @pnewvalue varchar(255), @pitemtype varchar(40) -- to be used if we need to do date comparisions etc. ) returns int as begin declare @vhaschanged tinyint set @vhaschanged = ( case when isnull(@pnewvalue, '') <> isnull(@poldvalue, '') and @pnewvalue is not null then 1 else 0 end ) return ( @vhaschanged ) end 




given an old value and a new value, determine if they<u+2019>re different. it<u+2019>s awkward and strange, with dead parameters coming to us from across the aeons, and an awkward case statement when an if would probably be clearer and easier to understand. but how, praytell, is this code used ? carpassword = ( case when dbo.fnvaluehaschanged(@locpasswordold, @locpassword, null) = 1 then @locpassword else @locpasswordold end ) 




the code which calls the function must be the same as the code within the function. thus, we have a case within a case, a mystery within a mystery, and a function which has ben handed down to us from the ancient ones. [advertisement] release! is a light card game about software and the people who make it. play with 2-5 people, or up to 10 with two copies - only $9.95 shipped!
codesod: the wisdom of the ancients
remy porter