Thanks all - agree rookie mistake with xor, had this been a C++ exercise I
would have have been OK - SQL seems to make my mind go blank...

Thanks for the case explanation Mark - v helpful.

Paul
www.sandersonforensics.com
skype: r3scue193
twitter: @sandersonforens
Tel +44 (0)1326 572786
http://sandersonforensics.com/forum/content.php?195-SQLite-Forensic-Toolkit
<http://sandersonforensics.com/forum/content.php?190-SQLite-Recovery>
-Forensic Toolkit for SQLite
http://sandersonforensics.com/forum/content.php?168-Reconnoitre - VSC
processing made easy


On 13 October 2014 16:30, Mark Lawrence <no...@null.net> wrote:

> My apologies for the previous completely wrong mesage. I got mixed up
> with operator meaning & precedence...
>
> On Mon Oct 13, 2014 at 02:39:40PM +0100, Paul Sanderson wrote:
> >
> > My actual code is as folows
> >
> >   (CASE visits.transition & 0xFFFFFF00  WHEN 0x00800000 THEN 'Blocked'
> >     ELSE '' END ||
>
> But I can at least put some better light on your issue. SQLite returns
> different results for your style of case/when construct:
>
>     CASE expr WHEN val THEN...
>
> and the alternative which I find reads easier:
>
>     CASE WHEN truth_expr THEN...
>
> Here's a demonstration:
>
>     WITH x
>     AS (
>         SELECT
>             0x01 AS a,
>             '0x01' AS txt
>         UNION ALL SELECT
>             0x10,
>             '0x10'
>         UNION ALL SELECT
>             0x01 | 0x10,
>             '0x01 | 0x10'
>     )
>     SELECT
>         x.txt,
>
>         CASE
>             WHEN x.a & 0x01
>             THEN 'A'
>             ELSE ''
>         END
>         || ' ' ||
>         CASE
>             WHEN x.a & 0x10
>             THEN 'B'
>             ELSE ''
>         END AS result1,
>
>         CASE x.a & 0xff
>             WHEN 0x01
>             THEN 'A'
>             ELSE ''
>         END
>         || ' ' ||
>         CASE x.a & 0xff
>             WHEN 0x10
>             THEN 'B'
>             ELSE ''
>         END AS result2
>     FROM
>         x
>     ;
>
> And the results:
>
>     txt         result1     result2
>     ----------  ----------  ----------
>     0x01        A           A
>     0x10         B           B
>     0x01 | 0x1  A B
>
> --
> MarkeLawrence
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to