You are viewing limited content. For full access, please sign in.

Question

Question

sql select where value in range variable

asked on February 5, 2024

Hi,

In my workflow, I use an SQL query to retrieve the last chrono number recorded in the database for specific categories.

My initial SQL query is :
SELECT COALESCE(MAX(num), 0) AS last_num
FROM table
WHERE YEAR(date_insert) = ? AND cat in (?) ;

My variables are
? = 2024
? = 'cat1', 'cat2'

In the end, this is what my SQL query looks like:
SELECT COALESCE(MAX(num), 0) AS last_num
FROM table
WHERE YEAR(date_insert) = 2024 AND cat in ('cat1', 'cat2') ;

I do get a return, but it doesn't give me the last number; instead, it gives me "0".

For your information, the last number in my database is "5".

I think the problem comes from the 2nd parameter "cat in ('cat1', 'cat2')".

0 0

Answer

SELECTED ANSWER
replied on February 5, 2024

Okay, I figured out how to do this on my own.
My parameter must be a token that supports multiple values, and each value must be on one line.

 

 

 

1 0
replied on February 6, 2024

FYI - your first one was probably putting ' characters around the value in addition to the ones you already had.  So when it got to the point of running the query, instead of 'cat1', 'cat2' it was actually looking like ''cat1', 'cat2''.

0 0
replied on February 6, 2024

Correct. Workflow uses parametrized queries so you can't inject extra values with a token that's a comma delimited list.

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.