--I have two Sql Server 2012 tables with data similar to these:
-- Table 1
Declare @Product_Sales Table (Suggested_Products varchar(max) null);
Insert Into @Product_Sales
Values
('({1421,1} OR {1422,2}) AND NOT ({1426,2},({1698,0} OR {1699,1} OR {1700,0})'),
('{1698,0} OR {1699,1} OR {1700,0}')
-- Table 2
Declare @Products Table (ProductID varchar(7) not null,Primary Key (ProductID), ProductName varchar(40) null);
Insert Into @Products
Values
('1421','Tangerine_s'),('1422','Tangerine_l'),('1426','Peruvian_Fig'),
('1698','Manila_Mango'),('1699','Passion_Fruit'),('1700','Concorde_Grape')
I cannot make updates to the tables as they get the data from an application. I need query returning results this way:
Products_Suggested (new column name)
1 (Tangerine_s OR Tangerine_l) AND NOT (Peruvian_Fig OR Manila_Mango OR Passion_Fruit OR Concorde_Grape)
2 Manila_Mango OR Passion_Fruit OR Concorde_Grape
Thank you very much in advance,
Rafael
-- Table 1
Declare @Product_Sales Table (Suggested_Products varchar(max) null);
Insert Into @Product_Sales
Values
('({1421,1} OR {1422,2}) AND NOT ({1426,2},({1698,0} OR {1699,1} OR {1700,0})'),
('{1698,0} OR {1699,1} OR {1700,0}')
-- Table 2
Declare @Products Table (ProductID varchar(7) not null,Primary Key (ProductID), ProductName varchar(40) null);
Insert Into @Products
Values
('1421','Tangerine_s'),('1422','Tangerine_l'),('1426','Peruvian_Fig'),
('1698','Manila_Mango'),('1699','Passion_Fruit'),('1700','Concorde_Grape')
I cannot make updates to the tables as they get the data from an application. I need query returning results this way:
Products_Suggested (new column name)
1 (Tangerine_s OR Tangerine_l) AND NOT (Peruvian_Fig OR Manila_Mango OR Passion_Fruit OR Concorde_Grape)
2 Manila_Mango OR Passion_Fruit OR Concorde_Grape
Thank you very much in advance,
Rafael