Parameterized Query using Excel Cell Value

JustinJ

New Member
Joined
Sep 19, 2020
Messages
14
Office Version
  1. 2013
Platform
  1. Windows
Hi everyone,
I have the query below (which works without issue) but I would like to use cells as parameters so users do not have to update the query itself.

SQL:
SELECT
        LINE_NUMBER,
        SHOP_ORDER_IDENTIFIER,
        SHOP_ORDER_OPERATION_IDENT,
        Upper(SO_OPERATION_DESCRIPTION) AS OP_DESC

FROM    BCDW_PROD_V.VL_SO_OPERATION_V

WHERE SOURCE_END_TS IS NULL
AND LINE_NUMBER >= 1060
AND LINE_NUMBER <= 1063
AND SHOP_ORDER_IDENTIFIER LIKE ANY ('FAD2_B_JB136_')
AND OP_DESC LIKE ANY ('%GAP%','%SAND%')

I have the LINE_NUMBER clauses figured out, I just do not know how to make this work for the two LIKE ANY clauses:

SQL:
SELECT
        LINE_NUMBER,
        SHOP_ORDER_IDENTIFIER,
        SHOP_ORDER_OPERATION_IDENT,
        Upper(SO_OPERATION_DESCRIPTION) AS OP_DESC

FROM    BCDW_PROD_V.VL_SO_OPERATION_V

WHERE SOURCE_END_TS IS NULL
AND LINE_NUMBER >= ? --WORKING
AND LINE_NUMBER <= ? --WORKING
AND SHOP_ORDER_IDENTIFIER LIKE ANY ? --NOT WORKING
AND OP_DESC LIKE ANY ? --NOT WORKING

I know the question mark alone doesn't work in teradata/sql. I am pasting this into excel.
 

Some videos you may like

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

JustinJ

New Member
Joined
Sep 19, 2020
Messages
14
Office Version
  1. 2013
Platform
  1. Windows
Edit:
If I don't use parenthesis around the question mark within the query then excel will not acknowledge the question mark. This forces me to use the parenthesis in the query around the question mark and the tick (') before and after each comma separated value. I believe that the preceding tick mark is falling off when running the query.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,592
Messages
5,625,681
Members
416,127
Latest member
MALEPINZON

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top