Hello.
I have 2 queries to search a table by differnent values. One query updates the table, the other doesn't, although clicking "save and run" returns the expected results.
This query works:
select * from dbo.SavedInventory WHERE ItemName LIKE {{'%' + textInput2.value + '%'}}
And only presents the relative items in the table
This query does not update the table. The table continues to show all values.
select * from dbo.SavedInventory WHERE ItemNum LIKE {{'%'+ textInput1.value + '%'}}
But when I execute it manually, it does return the expected results.
Ah, it's {{ NameSearch_SavedInventory.data }}
I tried adding {{BarcodeSearch_SavedInventory.data}} but it gives me... Invalid value. Try passing in an array of objects, or the result of a SQL Query with something like {{ query1.data }}
I also tried updating {{ NameSearch_SavedInventory.data }} to be...
select * from dbo.SavedInventory WHERE ItemName LIKE {{'%' + textInput2.value + '%'}} OR ItemNum LIKE {{'%' + textInput1.value + '%'}}
Ahh if you want to return the combined results of both searches instead of all rows that meet both criteria it's a bit trickier since any empty query will return all of the results. Does the above query work once you've entered a value into both fields?
I'm curious what you see if you try something like:
SELECT
*
FROM
dbo.SavedInventory
WHERE
{{ !textInput1.value && !textInput2.value }}
OR (
{{!!textInput2.value}}
AND ItemName LIKE {{'%' + textInput2.value + '%'}}
)
OR (
{{!!textInput1.value}}
AND ItemNum LIKE {{'%' + textInput1.value + '%'}}
)
That should check to see if both inputs are empty, return the full table if so, and otherwise only pull rows for inputs that actually have a value.
Playing with your code, this works as expected... except it doesn't update the table no matter the result...
SELECT * FROM dbo.SavedInventory WHERE (ISNULL({{textInput1.value}}, '') = '' AND ISNULL({{textInput2.value}}, '') = '')
OR (ISNULL({{textInput1.value}}, '') = '' AND ItemName LIKE {{'%' + textInput2.value + '%'}})
OR (ISNULL({{textInput2.value}}, '') = '' AND ItemNum LIKE {{'%' + textInput1.value + '%'}})
Ah! Are you using MSSQL? Sorry I hadn't noticed earlier if so
Can you try one of the following?
SELECT * FROM dbo.SavedInventory WHERE ({{textInput1.value ? 0 : 1}} = 1 AND {{textInput2.value ? 0 : 1}} = 1)
OR ({{textInput1.value ? 1 : 0}} = 1 AND ItemName LIKE {{'%' + textInput1.value + '%'}})
OR ({{textInput2.value ? 1 : 0}} = 1 AND ItemNum LIKE {{'%' + textInput2.value + '%'}})
or
SELECT * FROM dbo.SavedInventory WHERE ({{textInput1.value || null}} IS NULL AND {{textInput2.value || null}} IS NULL)
OR ({{textInput1.value || null}} IS NOT NULL AND ItemName LIKE {{'%' + textInput1.value + '%'}})
OR ({{textInput2.value || null}} IS NOT NULL AND ItemNum LIKE {{'%' + textInput2.value + '%'}})
The first reference to each text input should return true if the text input is empty which ISNULL({{textInput1.value}}, '') = '' works well for, but the second reference needs to return true if the text input is *non-empty *since we only want to add values from those filters if the user has actually entered something.