[In the message "Re: [sqlite] Re: Re: how do i declare and use variables in 
sqlite?" on Aug 3, 11:47, "Paul Harris" writes:]
> > >> create temporary table vars (name text, value something);
> > >> --
> > >> insert into vars set name="x", value=0;
> > >> --
> > >> ... where something = (select value from vars where name="x")...
> > >>
> > >
> > > I tried doing this, but there doesn't seem to be a way to do the same
> > > thing with an UPDATE command ?
> >
> > No way to do what with UPDATE command? What exactly are you trying to
> > do, and failing?
> >
> 
> i've just realised the last statement ("...where etc etc") is probably
> supposed to be part of a select statement.

Yeap, sorry for being "too conceptual", dislexic (insert/update, thanks Igor)
and obviously too confusing :-).


> anyway, this is what i'm trying to do:
> 
> eg 1
> select @somevar := column1 from table1;
> update table2 set column2 = @somevar;

Try:

create temporary table var1 select column1 from table1;
update table2 set column2 = (select column1 from var1);

As written the second comand will likely not do what was intended
since var1 might have more than 1 row and there is no constraint
so every row in table2 will be affected. I assume that real
implementation will deal with this.

> 
> eg2
> update table1,table2 set column2=column1;

I believe that SQLite only updates one table at the time, so 
this will have to be rewriten, but where is the variable here?

Perhaps:

update table2 set column2=(select column1 from table1);

with some where clauses?

> 
> eg3 (using temp table - how to do this?)
>  create temporary table vars (name text, value something);
>  insert into vars set name="x", value=0;
>  update vars,table2 set column2=value where name = 'x';

Is the code above (eg1) what you are lookin after?

Nikola

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to