Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>WITH T AS ( SELECT PD.Id AS ProductId, sao.Id AS SpecificationAttributeOptionId, '1' AS AllowFiltering, '0' AS ShowOnProductPage, sao.DisplayOrder AS DisplayOrder FROM Product as PD join ( select id, name, ymin as pcmin, case when ymax &lt; ymin then 99 else ymax end as pcmax, case when ymax &lt; ymin then 0 else ymin end as ccmin, ymax as ccmax from ( select id, name, convert(int, SUBSTRING(name, loc-2, 2)) as ymin, convert(int, SUBSTRING(name, loc+1, 2)) as ymax from ( select id, name, loc from ( select id, name, CHARINDEX('-', name) as loc from PRODUCT where CHARINDEX('-', name) &gt; 0 ) as tbl where SUBSTRING(name, loc-3, 1) = ' ' and SUBSTRING(name, loc+3, 1) = ' ' ) as rng ) as yrs ) as PdRng on PdRng.id = PD.id join ( select * from SpecificationAttributeOption where isnumeric(Name) &gt; 0 and len(rtrim(Name)) = 4 AND SpecificationAttributeOption.SpecificationAttributeId = '7' ) as sao ON convert(int, Right(sao.Name, 2)) between PdRng.pcmin and PdRng.pcmax OR convert(int, Right(sao.Name, 2)) between PdRng.ccmin and PdRng.ccmax ) INSERT INTO Product_SpecificationAttribute_Mapping( ProductId, SpecificationAttributeOptionId, AllowFiltering, ShowOnProductPage, DisplayOrder ) SELECT ProductId, SpecificationAttributeOptionId, AllowFiltering, ShowOnProductPage, DisplayOrder FROM T WHERE NOT EXISTS ( SELECT * FROM Product_SpecificationAttribute_Mapping M WHERE T.ProductId = M.ProductId AND T.SpecificationAttributeOptionId = M.SpecificationAttributeOptionId AND T.AllowFiltering = M.AllowFiltering AND T.ShowOnProductPage = M.ShowOnProductPage AND T.DisplayOrder = M.DisplayOrder ) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload