On 14/12/2011, at 10:04 AM, Grace Batumbya wrote:

> Since SQLite does not support stored procedures, what are some workarounds 
> that are used to accomplish things like executing a statement based on a 
> conditional.
> For example.
> 
> IF value OF column IN tableX  == 'foo'
> DO statement 1
> ELSE statement 2

SQL isn't a procedural language. It doesn't have branching like if/then or 
for/repeat loops. It uses set logic instead.

So, instead of saying "for each item in the table, if it meets this condition 
then update that", in SQL you instead say "update that in the table where it 
meets this condition"

If depends on what your statement 1 and statement 2 are. Let's say that they 
are update statements, then your above example would look something like:

update tableX set column2 = 'match' where "column" = 'foo';
update tableX set column2 = 'no match' where "column" != 'foo';

Tom
BareFeetWare

--
iPhone/iPad/iPod and Mac software development, specialising in databases
develo...@barefeetware.com
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to