1

I want to use variable in my query for sqlite but I don't know how do it?

my query is it :

/*I want to declare my variable in here and use this variable query*/

/*declare vaiable*/SELECT direct_station.iddirect_station,station.name,line.color FROM direct_station JOIN
direction ON direction.iddirection = direct_station.iddirection JOIN
station ON station.idstation = direction.laststation JOIN line ON line.idline = direction.line WHERE direct_station.idstation = /*put variable*/

Explain :

my friends I want execute one query but this query have two part :

first part I want to get several value like this {178,180,200,300}. I got this from this query :

SELECT direct_station.iddirect_station FROM direct_station WHERE direct_station.idstation = 98

and second part I want to use any these values to this query by one variable :

SELECT * FROM stations_view WHERE iddirection = %d

now I want to get any value from second query that joined to first query.

MKFB
  • 185
  • 1
  • 11
  • Appears to be a similar question http://stackoverflow.com/questions/7739444/declare-variable-in-sqlite-and-use-it – f01 Oct 29 '14 at 14:13
  • @f01 this not working for me – MKFB Oct 29 '14 at 14:15
  • What is the purpose of the variable? Are you trying to write a recursive query? – CL. Oct 29 '14 at 15:46
  • @CL. I don't know about recursive query but I want one query like for loop that include from two part (first part get 4 value for example 1,2,3,4 and second part take this values tandem) please guide me about it.... – MKFB Oct 29 '14 at 16:25
  • I think maybe I want to write recursive query. do you explain about that? – MKFB Oct 29 '14 at 16:45
  • Edit the question to show example data and the desired result. – CL. Oct 29 '14 at 18:07

1 Answers1

0

I think that the solution could be to create a Table for your variable where you are going to store the variable's value and from where you can retrieve the value when needed.

INSERT INTO VariableTable (Variable) VALUES ('x');

SELECT * FROM TableName WHERE ColumnName = (SELECT Variable FROM VariableTable);
matteo
  • 1,635
  • 1
  • 15
  • 26