[dba-SQLServer] Strange syntax

Stuart McLachlan stuart at lexacorp.com.pg
Wed Sep 14 03:08:06 CDT 2011


Just noticed another cunning piece of obfuscation in there:

,B = 1 -- 1

The "--" is a comment delimiter so this is the same as

,B = 1  /* 1 */
and not
,B = 1 - (-1)

So the field B returns 1, not 2.

-- 
Stuart

On 14 Sep 2011 at 17:48, Stuart McLachlan wrote:

> On 14 Sep 2011 at 2:32, Arthur Fuller wrote:
> 
> > Yeah OK I get it, I'm way out of the loop. But catch me up, please.
> > I still don't understand why or how this works.
> > 
> > If you have a spare moment, please explain.
> > 
> 
> It's actually quite simple once you dig through the obfuscation.
> 
> You don't need the DECLARE and PRINT lines at all to return the
> recordset in question,  They just returning the string "Result = Null"
> as an "informational error message" to the calling application. (Null
> because although @b is declared, it is not initialised with a SET @b
> =....."  )
> 
> The recordset comes purely from the select part which is just using
> different ways of declaring field aliases and using concatentation of
> +/- operators..You get exactly the same recordset returned with:  
> 
> SELECT 0  AS A,
> 1 - (-1) AS B,
> 1 + (+1) AS C,
> 1 + (- (+1)) AS D,
> 1 - (+ ( -1)) AS E,
> 1 - (-1) AS  F
> 
> or
> SELECT A = 0,
> B = 1 - (-1),
> C = .....
> 
> Note the field alias B is not the integer variable @b.  Using the same
> letter for both is just further obfuscation.
> 
> 
> _______________________________________________
> dba-SQLServer mailing list
> dba-SQLServer at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
> http://www.databaseadvisors.com
> 
> 






More information about the dba-SQLServer mailing list