Skip to main content
1-Visitor
January 15, 2014
Question

SQL Where clause

  • January 15, 2014
  • 2 replies
  • 2106 views

I'm trying to setup a SQL query with a Where clause that have an input from the user but I still want the user to be able to select all values underneath a column if they want or a specific one. My example query looks as follows.

Select (value) from (table) where (columname) = (inputfromuser)

I don't know what to put as the input from the user if they want to see all the values contained in the table without having to choose a specific value from within the column but still have the option available.

2 replies

11-Garnet
January 16, 2014

One way to accomplish this would be to setup a SQL Query Service with an input parameter (in the example below named whereClause):

SELECT *

FROM branch

<<whereClause>>


Then have a 'wrapper' JavaScript Service that calls this query passing it in the statement you need based on the users selection, i.e. Branch123 or just an empty string "" for everything. Another option would be to always select everything in the SQL Query and then just filter it using InfoTable functions in the 'wrapper' JavaScript Service...





1-Visitor
January 16, 2014

Andy,

Not exactly understanding 100% what you are describing I should do.


Is there anyway I can put on if statement in the query such as


if [[Shift]] = '' then

DECLARE Shiftinput = "and Shift = [[Shift]]"

else

DECLARE Shiftinput = ""


basically stating if the user has put a value into the input for "Shift" then add the where clause on to the end of the query designated by the variable "Shiftinput" otherwise don't add the where clause on the end of the query by having the variable "Shiftinput" which is at the end of the query statement to be equal to nothing?