Search code examples
sqlintersystems-cache-zen

Select all facts even when WHERE clause is present


I know this might sound strange and I can certainly work around my problem. I am using SQL on server side code and a statement is similar to the following:

SELECT myCol FROM mytable WHERE myCol2=url_parameter

url_parameter is a string passed through the URL. Is there any way to set url_parameter to something but still get all facts in the table?


Solution

  • The normal way to handle this is by having a query that looks like:

    SELECT myCol
    FROM mytable
    WHERE myCol2 = url_parameter OR url_parameter IS NULL;  -- or url_parameter = '';
    

    If you were munging the SQL string instead of passing a parameter, you could insert the value myCol2 (without quotes) when you want to get all values. However, you should be using parameters.