SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 Hiding fields from Feed
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

deanglen
Starting Member

40 Posts

Posted - 08/08/2012 :  05:45:15  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

5152 Posts

Posted - 08/08/2012 :  06:56:49  Show Profile  Reply with Quote
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
....
Go to Top of Page

deanglen
Starting Member

40 Posts

Posted - 08/08/2012 :  07:13:06  Show Profile  Reply with Quote
Thanks I tried but but get

Exception=The data types ntext and varchar are incompatible in the equal to operator.<br/>

Go to Top of Page

sunitabeck
Flowing Fount of Yak Knowledge

5152 Posts

Posted - 08/08/2012 :  07:17:22  Show Profile  Reply with Quote
Change it to:
AND NULLIF(CAST(p.description AS VARCHAR(MAX)),'') IS NOT NULL
Go to Top of Page

deanglen
Starting Member

40 Posts

Posted - 08/08/2012 :  07:24:45  Show Profile  Reply with Quote
Fixed it! THanks!
Go to Top of Page

banwuin1
Starting Member

1 Posts

Posted - 08/08/2012 :  23:27:53  Show Profile  Reply with Quote
Thank you for this article.Really impressed! Everything is very, very clear, open is a description of the problem. It contains the information.

unspammed
john andy
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000