0

I am building an automated productselection. I want to add rows to a DE based on record count. So far Ive come up with underneath solution, but the syntax is not right: An error occurred while checking the query syntax. Errors: Incorrect syntax near ')'.

So when the DE holds 3 rows, i want to add 3 more to al totall of 6. Could use some help.

SELECT Product_id, product_name, product_url, image_url, currency, availability, brand, color, material, product_type, Energylabels_imageURL, reviewstars_Image_url, price, Vanaf_prijs, stock, [from_date], [end_date], [sale_price], 
    
    CASE WHEN COUNT(Product_id) = 6 
    THEN ( Select top 0
    Product_id, product_name, product_url, image_url, currency, availability, brand, color, material, product_type, Energylabels_imageURL, reviewstars_Image_url, price, Vanaf_prijs, stock, [from_date], [end_date], [sale_price] 
    FROM [LenL_productfeed_EE_Troubleshooting]
    WHERE stock  > 10 AND [from_date] IS NOT NULL AND [end_date] IS NOT NULL AND [sale_price] IS NOT NULL )  ELSE
    
    CASE WHEN COUNT(Product_id) = 5 
    THEN ( Select top 1
    Product_id, product_name, product_url, image_url, currency, availability, brand, color, material, product_type, Energylabels_imageURL, reviewstars_Image_url, price, Vanaf_prijs, stock, [from_date], [end_date], [sale_price] 
    FROM [LenL_productfeed_EE_Troubleshooting]
    WHERE stock  > 10 AND [from_date] IS NOT NULL AND [end_date] IS NOT NULL AND [sale_price] IS NOT NULL ) ELSE  
    
    CASE WHEN COUNT(Product_id) = 4 
    THEN ( Select top 2
    Product_id, product_name, product_url, image_url, currency, availability, brand, color, material, product_type, Energylabels_imageURL, reviewstars_Image_url, price, Vanaf_prijs, stock, [from_date], [end_date], [sale_price] 
    FROM [LenL_productfeed_EE_Troubleshooting]
    WHERE stock  > 10 AND [from_date] IS NOT NULL AND [end_date] IS NOT NULL AND [sale_price] IS NOT NULL ) ELSE
    
    CASE WHEN COUNT(Product_id) = 3 
    THEN ( Select top 3
    Product_id, product_name, product_url, image_url, currency, availability, brand, color, material, product_type, Energylabels_imageURL, reviewstars_Image_url, price, Vanaf_prijs, stock, [from_date], [end_date], [sale_price] 
    FROM [LenL_productfeed_EE_Troubleshooting]
    WHERE stock  > 10 AND [from_date] IS NOT NULL AND [end_date] IS NOT NULL AND [sale_price] IS NOT NULL ) ELSE
     
    CASE WHEN COUNT(Product_id) = 2 
    THEN ( Select top 4
    Product_id, product_name, product_url, image_url, currency, availability, brand, color, material, product_type, Energylabels_imageURL, reviewstars_Image_url, price, Vanaf_prijs, stock, [from_date], [end_date], [sale_price] 
    FROM [LenL_productfeed_EE_Troubleshooting]
    WHERE stock  > 10 AND [from_date] IS NOT NULL AND [end_date] IS NOT NULL AND [sale_price] IS NOT NULL) ELSE
    
    CASE WHEN COUNT(Product_id) = 1 
    THEN ( Select top 5
    Product_id, product_name, product_url, image_url, currency, availability, brand, color, material, product_type, Energylabels_imageURL, reviewstars_Image_url, price, Vanaf_prijs, stock, [from_date], [end_date], [sale_price] 
    FROM [LenL_productfeed_EE_Troubleshooting]
    WHERE stock  > 10 AND [from_date] IS NOT NULL AND [end_date] IS NOT NULL AND [sale_price] IS NOT NULL) ELSE
    
    CASE WHEN COUNT(Product_id) = 0 
    THEN ( Select top 6
    Product_id, product_name, product_url, image_url, currency, availability, brand, color, material, product_type, Energylabels_imageURL, reviewstars_Image_url, price, Vanaf_prijs, stock, [from_date], [end_date], [sale_price] 
    FROM [LenL_productfeed_EE_Troubleshooting]
    WHERE stock  > 10 AND [from_date] IS NOT NULL AND [end_date] IS NOT NULL AND [sale_price] IS NOT NULL)  END

Kind regards, Rob

1
  • I dont think above is gonna work with case statements, are there any suggestions for my problem? – RobSource May 3 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.