# Select Query with input variable

**URL:** <https://forum.cloverdx.com/t/select-query-with-input-variable/996>\
**Category:** CloverDX Platform\
**Created:** [January 11, 2012, 12:00am UTC](https://forum.cloverdx.com/t/select-query-with-input-variable/996 "2012-01-11T00:00:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![faldarod](https://avatars.discourse-cdn.com/v4/letter/f/97f17d/32.png) [@faldarod](https://forum.cloverdx.com/u/faldarod)\
**Post date:** [January 11, 2012, 12:00am UTC](https://forum.cloverdx.com/t/select-query-with-input-variable/996/1 "2012-01-11T00:00:00Z")

</div>

Hi guys,

Im trying out an select statement, so i can see what primary key certrain varaibles got. How do i do this? I have tryed it with the DBExecute. This give the following error  
SELECT via executeUpdate(). I also tryed the DBJoin, but cant figure out how to use the input variables on the ? places.

```auto
SELECT $PatientID:=patient.PatientID, $BehandelaarID:= behandelaar.BehandelaarID
From patient , behandelaar
WHERE patient.Naam = ?
  AND behandelaar.Naam = ? 

```

---

<div class="post-metadata">

**Author:** ![julrych](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@julrych](https://forum.cloverdx.com/u/julrych)\
**Post date:** [January 11, 2012, 2:21pm UTC](https://forum.cloverdx.com/t/select-query-with-input-variable/996/2 "2012-01-11T14:21:50Z")

</div>

Hi Faldarod,

The best way to implement what you are attempting to do is using LookupJoin. Question marks in query are automatically replaced by values from fields specified as Join key in respective order.

The attached graph illustrates that. You will just need to configure connection to database and provide some meaningful data in DataGenerator. I split the query into two queries - one for patient and another for behandelaar. Otherwise you would get cartesian product of the tables which I do not suppose is what you expect.

- [SelectFromDB.grf](https://cdn.cloverdx.com/forum/11799%5Faaf69a2c2717e1ba4d6452fc1c3630a6/SelectFromDB.grf)
