Parameterized Query using Excel Cell Value

JustinJ

New Member
Joined
Sep 19, 2020
Messages
16
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.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
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.
 
Upvote 0

Forum statistics

Threads
1,223,270
Messages
6,171,103
Members
452,379
Latest member
IainTru

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
Back
Top