August 20, 2018 at 2:30 am
I have 157 values (varchar) in a table but I am only interested in say 50 of these strings. So it's a simple where clause basically but I don't want to do 50 AND's, so I'm thinking about an IN operator on the where. Thing is I have two CTE's and I want to do this in BOTH CTE's.
Is there any way of storing all these values in something like an array and reusing it wherever I want in SQL Server?
August 20, 2018 at 3:11 am
NikosV - Monday, August 20, 2018 2:30 AMI have 157 values (varchar) in a table but I am only interested in say 50 of these strings. So it's a simple where clause basically but I don't want to do 50 AND's, so I'm thinking about an IN operator on the where. Thing is I have two CTE's and I want to do this in BOTH CTE's.Is there any way of storing all these values in something like an array and reusing it wherever I want in SQL Server?
Can you please post the DDL (create table) script, sample data as an insert statement and the desired results!
😎
August 20, 2018 at 7:28 am
NikosV - Monday, August 20, 2018 2:30 AMI have 157 values (varchar) in a table but I am only interested in say 50 of these strings. So it's a simple where clause basically but I don't want to do 50 AND's, so I'm thinking about an IN operator on the where. Thing is I have two CTE's and I want to do this in BOTH CTE's.Is there any way of storing all these values in something like an array and reusing it wherever I want in SQL Server?
Yes, it's called a table. You can either store the values you're interested in in a table, temp table, or table variable or you can add a column to the current table to flag the ones that you are interested in.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
August 20, 2018 at 10:58 am
drew.allen - Monday, August 20, 2018 7:28 AMNikosV - Monday, August 20, 2018 2:30 AMI have 157 values (varchar) in a table but I am only interested in say 50 of these strings. So it's a simple where clause basically but I don't want to do 50 AND's, so I'm thinking about an IN operator on the where. Thing is I have two CTE's and I want to do this in BOTH CTE's.Is there any way of storing all these values in something like an array and reusing it wherever I want in SQL Server?
Yes, it's called a table. You can either store the values you're interested in in a table, temp table, or table variable or you can add a column to the current table to flag the ones that you are interested in.
Drew
Thanks!
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply