Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
deanglen
Yak Posting Veteran
65 Posts |
Posted - 2012-08-08 : 05:45:15
|
Hi The SQL below forms part of an XML Feed file for Google. Do you know if it is possible to change the SQL so that it DOES NOT include products that have an empty description? <sql> <![CDATA[ select p.productid, p.name, isnull(pv.name, '') VariantName, p.description, p.sename, p.ImageFileNameOverride, p.SKU, isnull(p.FroogleDescription, '') ProductFroogleDescription, p.SEKeywords, m.Name brand, p.ManufacturerPartNumber, pv.price, isnull(pv.saleprice, 0) saleprice, isnull(pv.FroogleDescription, '') VariantFroogleDescription, isnull(pv.description, '') VariantDescr, pv.inventory, ROW_NUMBER() OVER (ORDER BY p.productid) AS ROW from dbo.product p join dbo.productvariant pv on p.productid = pv.productid join dbo.ProductManufacturer pm on pm.ProductID = p.ProductID join dbo.Manufacturer m on m.ManufacturerID = pm.ManufacturerID join dbo.ProductStore ps on ps.ProductID = p.ProductID and ps.StoreID = 1 left join (select variantid, sum(quan) inventory from dbo.inventory group by variantid) i on pv.variantid = i.variantid where p.IsSystem=0 and p.deleted = 0 and p.published = 1 and p.ExcludeFromPriceFeeds = 0 and pv.isdefault = 1 and case p.TrackInventoryBySizeAndColor when 1 then isnull(i.inventory, 0) else pv.inventory end >= @HideProductsWithLessThanThisInventoryLevel ]]> </sql> |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-08-08 : 06:56:49
|
quote: Originally posted by deanglen Hi The SQL below forms part of an XML Feed file for Google. Do you know if it is possible to change the SQL so that it DOES NOT include products that have an empty description? <sql> <![CDATA[ select p.productid, p.name, isnull(pv.name, '') VariantName, p.description, p.sename, p.ImageFileNameOverride, p.SKU, isnull(p.FroogleDescription, '') ProductFroogleDescription, p.SEKeywords, m.Name brand, p.ManufacturerPartNumber, pv.price, isnull(pv.saleprice, 0) saleprice, isnull(pv.FroogleDescription, '') VariantFroogleDescription, isnull(pv.description, '') VariantDescr, pv.inventory, ROW_NUMBER() OVER (ORDER BY p.productid) AS ROW from dbo.product p join dbo.productvariant pv on p.productid = pv.productid join dbo.ProductManufacturer pm on pm.ProductID = p.ProductID join dbo.Manufacturer m on m.ManufacturerID = pm.ManufacturerID join dbo.ProductStore ps on ps.ProductID = p.ProductID and ps.StoreID = 1 left join (select variantid, sum(quan) inventory from dbo.inventory group by variantid) i on pv.variantid = i.variantid where p.IsSystem=0 and p.deleted = 0 and p.published = 1 and p.ExcludeFromPriceFeeds = 0 and pv.isdefault = 1 and case p.TrackInventoryBySizeAndColor when 1 then isnull(i.inventory, 0) else pv.inventory end >= @HideProductsWithLessThanThisInventoryLevel ]]> </sql>
Add another condition to the where clause as shown below:.... AND CASE p.TrackInventoryBySizeAndColor WHEN 1 THEN ISNULL(i.inventory, 0) ELSE pv.inventory END >= @HideProductsWithLessThanThisInventoryLevel AND NULLIF(p.description,'') IS NOT NULL.... |
|
|
deanglen
Yak Posting Veteran
65 Posts |
Posted - 2012-08-08 : 07:13:06
|
Thanks I tried but but getException=The data types ntext and varchar are incompatible in the equal to operator.<br/> |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-08-08 : 07:17:22
|
Change it to:AND NULLIF(CAST(p.description AS VARCHAR(MAX)),'') IS NOT NULL |
|
|
deanglen
Yak Posting Veteran
65 Posts |
Posted - 2012-08-08 : 07:24:45
|
Fixed it! THanks! |
|
|
banwuin1
Starting Member
1 Post |
Posted - 2012-08-08 : 23:27:53
|
Thank you for this article.Really impressed! Everything is very, very clear, open is a description of the problem. It contains the information.unspammedjohn andy |
|
|
|
|
|
|
|