On Thursday, January 06, 2011 9:09 AM, stunner Easwar wrote: > I need to use local variables similar to sql syntax using DECLARE. My > project involves lot of places where I need to select values from > different > tables and insert it into one table. In most of the cases creation of view > is also not feasible. Any alternative for DECLARE.
As far as I am aware, there is no direct solution for what you want. If you are willing to code some custom functions (see http://www.sqlite.org/c3ref/create_function.html), then you could create a workaround for yourself. I would suggest something along the lines of: set_var(var_name, value) -- create or set existing variable get_var(var_name) -- get value from variable del_var(var_name) -- clear out variable in this case "set_var" could add the variable to a global or connection-specific hash-table, and "del_var" can be used to remove it when you're done (and to free memory). Its use is still a little clunky, but it might be the best you can get. Some examples of its use: SELECT set_var('var1', 15); -- set var1 to 15 SELECT set_var('var2', a) FROM tab WHERE rowid=1; -- set var2 to value from table SELECT a, b, c FROM tab WHERE a = get_var('var2'); -- select from table using variable SELECT del_var('var2'); -- delete variable Of course, there are still things that need to be worked out in the implementation (e.g. what do you want to happen if you do something like "SELECT set_var('var', a) FROM tab" and it returns more than one row?), but this might get you started. The alternative to all this, is just to embed sqlite into an application/script that stores the variables for you. Andy _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users