SQLite Forum

Re-use and execute SQL code stored in tables (eval?)
Login
Hey, I know this has already probably been answered, but is it possible to re-use the content of a table cell in a query?

Not just executing a query stored in a table, but using one of its columns as SQL code for another query.

For example:

```
CREATE TABLE user_pricings (condition TEXT);
CREATE TABLE users (name, age);
INSERT INTO users ('bohwaz', 42);
INSERT INTO user_pricings ('CASE WHEN age < 18 THEN 42.00 ELSE 55.00 END');

SELECT *, `(SELECT condition FROM user_pricings)` FROM users;
```

Which would be interpreted as:

```
SELECT *, CASE WHEN age < 18 THEN 42.00 ELSE 55.00 END FROM users;
```

Thanks :)