Inserting Values Using a subquery

Viewed 36

I am creating a temp table and inserting values into it. It's really meant to be a table where I can map certain labels back to their desired value.

The issue is that I want to use the like operator in the values statement.

How can I do something like the following where I can take all values that meet a LIKE condition and assign it with a specific value (vbc)?

Any other better approaches are also appreciated?

insert into #new_cohort
(
chosen_path,
abr_cohort
)
values
('core', 'core'),
('pod', 'core'),
('Dynamic High - CORE', 'Core_High'),
('Dynamic High - POD','Core_High'),
((SELECT routing_path FROM [bid].[propensity_path_cutoffs] 
  WHERE routing_path like '%vbc%'
  and routing_path not like '%Dynamic High%'), 'vbc')
1 Answers

I think you can do like this :

insert into #new_cohort (chosen_path, abr_cohort)
values
('core', 'core'),
('pod', 'core'),
('Dynamic High - CORE', 'Core_High'),
('Dynamic High - POD','Core_High');
  

insert into #new_cohort (chosen_path, abr_cohort)
SELECT routing_path, 'vbc' FROM [bid].[propensity_path_cutoffs] 
WHERE routing_path like '%vbc%'
and routing_path not like '%Dynamic High%')
Related