SQL query other than "case when...then"

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
sacgtdev
Veteran Member
Posts: 48
Joined: 2020-06-10 11:14

SQL query other than "case when...then"

Post by sacgtdev » 2021-09-09 13:38

Table A
Value
3

How to do a sql query to assign 'medium' based on the value in the Table A? The category will be referenced from Table B.
I can think of case when...then (hard-code) in the sql query. Is there any alternative way to write the query?

Table B
Category Min Max
Low 0 2.99
Medium 3 4.99
High 5 5.99

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1027
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: SQL query other than "case when...then"

Post by onoehring » 2021-09-09 17:04

Hi,

try something like this (pseudo code)

Code: Select all

$sql = "select category from tableB where min <= " . $value . " AND max >" . $value . ";"
$result= sqlValue($sql)
PS: You need only min or max in your table, as the other one automatically is pure logic - your SQL will probably get more complex
PSPS: You should use different fieldnames (not min and max).

Olaf

sacgtdev
Veteran Member
Posts: 48
Joined: 2020-06-10 11:14

Re: SQL query other than "case when...then"

Post by sacgtdev » 2021-09-10 09:37

Thanks. Your suggestion work in php.

Just wonder how to implement this to the calculated field. As I now there is pesudo code for id, primary key and table..

but, how to custom a pseudo-code?

Post Reply