October 22, 2024
Chicago 12, Melborne City, USA
SQL

how to create a variable list for WHERE/IN function?


I have a huge list of IDs I’m searching through from a large data set.
When I try to search for the IDs using IN, it says I’ve gone beyond character limits so won’t run.

If I’m to split these into manageable size (see below) it’d take me really long time due to the size.

Is it possible to have a variable that contains all the list of IDs I want, and in the where function use IN VAR?

If I am to split into smaller chunks

(customer_id in ('1', '2', '3', ..., '1000')
or
customer_id in ('1001', '1002', '1003', ..., '2000')
or
customer_id in ('2001', '2002', '2003', ..., '3000'))

What I want (verbatim)

Cust_ID_List IN (‘1’, ‘2’, ‘3’, … ‘3000’) — VARAIBLE

SELECT * FROM DATA
WHERE ID IN Cust_ID_List



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video