# Two queries - different?

**URL:** <https://forum.servoy.com/t/two-queries-different/16499>\
**Category:** Classic Servoy\
**Created:** [September 19, 2012, 1:26am UTC](https://forum.servoy.com/t/two-queries-different/16499 "2012-09-19T01:26:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![djlapin](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@djlapin](https://forum.servoy.com/u/djlapin)\
**Post date:** [September 19, 2012, 1:26am UTC](https://forum.servoy.com/t/two-queries-different/16499/1 "2012-09-19T01:26:35Z")

</div>

I’m not getting the results I expect when I perform a Servoy-style search.

Is there a difference between this,

```auto
queryText = "SELECT std_student_id FROM student";
queryText += " JOIN transport_action ON (trn_student_id = std_student_id)";
queryText += " WHERE trn_action_category = \'request\' AND";
queryText += " trn_req_start_d IS NOT NULL AND";
queryText += " trn_req_start_d::date >= \'" + utils.dateFormat(transRequestSince_D,"yyyy-MM-dd") + "\'";		
fs.loadRecords(queryText, null);

```

and this,

```auto
fs.find();
 fs.student_to_transport_action.trn_action_category = 'request';
fs.student_to_transport_action.trn_req_start_d = "!^"; // is not null
fs.student_to_transport_action.trn_req_start_d = ">=" + utils.dateFormat(transRequestSince_D,"yyyy-MM-dd");
fs.search();

```

Thank you,  
Don

---

<div class="post-metadata">

**Author:** ![ngervasi](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@ngervasi](https://forum.servoy.com/u/ngervasi)\
**Post date:** [September 19, 2012, 8:01am UTC](https://forum.servoy.com/t/two-queries-different/16499/2 "2012-09-19T08:01:11Z")

</div>

Why are you escaping the single quotes? You can also use the \ (backslash) to get a cleaner code like this:

```auto
queryText = "SELECT std_student_id FROM student \
 JOIN transport_action ON (trn_student_id = std_student_id) \
 WHERE trn_action_category = 'request' AND \
 trn_req_start_d IS NOT NULL AND \
 trn_req_start_d::date >= '" + utils.dateFormat(transRequestSince_D,"yyyy-MM-dd") + ' "  

fs.loadRecords(queryText, null);

```

Beside that they should generate the same query.

Another hint, don’t hardcode parameters inside the query, use prepared statements:

```auto
queryText = "SELECT std_student_id FROM student \
 JOIN transport_action ON (trn_student_id = std_student_id) \
 WHERE trn_action_category = ? AND \
 trn_req_start_d IS NOT NULL AND \
 trn_req_start_d::date >= ? "  

fs.loadRecords(queryText, ['request',utils.dateFormat(transRequestSince_D,"yyyy-MM-dd")]);

```

---

<div class="post-metadata">

**Author:** ![djlapin](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@djlapin](https://forum.servoy.com/u/djlapin)\
**Post date:** [September 19, 2012, 5:54pm UTC](https://forum.servoy.com/t/two-queries-different/16499/3 "2012-09-19T17:54:42Z")

</div>

Hi Nicola,

The sql is generating the results that I expect to get. The Servoy statement does not. Is there something about the way the Servoy statement is constructed that causes it to fail?

Thanks for the hints on the sql statements.

Don

---

<div class="post-metadata">

**Author:** ![ngervasi](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@ngervasi](https://forum.servoy.com/u/ngervasi)\
**Post date:** [September 19, 2012, 6:13pm UTC](https://forum.servoy.com/t/two-queries-different/16499/4 "2012-09-19T18:13:11Z")

</div>

Is trn\_req\_start\_d a datetime column? Is transRequestSince\_D a datetime object?

Doing like this:

```auto
fs.student_to_transport_action.trn_req_start_d = "!^"; // is not null
fs.student_to_transport_action.trn_req_start_d = ">=" + utils.dateFormat(transRequestSince_D,"yyyy-MM-dd");

```

You are overwriting the search request so basically the first line of code is useless, altough I guess it’s not important since any date is greater than null.

What do you actually store in the trn\_action\_category colum? ‘request’ or request (with or without the single quotes)?

---

<div class="post-metadata">

**Author:** ![ngervasi](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@ngervasi](https://forum.servoy.com/u/ngervasi)\
**Post date:** [September 19, 2012, 6:16pm UTC](https://forum.servoy.com/t/two-queries-different/16499/5 "2012-09-19T18:16:57Z")

</div>

Woops, I noticed only now an error in your code, when searching over a datetime column you have to do like this (notice the last string with the pipe char):

```auto
fs.student_to_transport_action.trn_req_start_d = '>='+utils.dateFormat(transRequestSince_D,'yyyy-MM-dd')+'|yyyy-MM-dd'

```

Probably that’s the reason of your code failing.

---

<div class="post-metadata">

**Author:** ![djlapin](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@djlapin](https://forum.servoy.com/u/djlapin)\
**Post date:** [September 19, 2012, 9:59pm UTC](https://forum.servoy.com/t/two-queries-different/16499/6 "2012-09-19T21:59:26Z")

</div>

Both the column and the variable are datetime. But you hit the nail on the head with the pipe character. I knew at one time to do that, but forgot.

Thank you, Nicola! - Don
