How to get Category Name in SQL for Product?

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
Mike718NY
Commodore (COMO)
Commodore (COMO)
Posts: 485
Joined: Wed Jun 18, 2008 5:24 pm

How to get Category Name in SQL for Product?

Post by Mike718NY » Sat Dec 15, 2012 6:18 pm

Is there a way to join some tables to get the Category Name?
I was able to get the Manufacture name, but I can't see how to join the Category Table.

SELECT [ac_Products].[Name]
,[Price]
,[MSRP]
,ac_Manufacturers.Name as 'Manufacturer'
,[Sku]
,[ImageUrl]
,[Description]
,[VisibilityId]
FROM [super-v_store].[dbo].[ac_Products]
left JOIN ac_Manufacturers ON ac_Products.ManufacturerId = ac_Manufacturers.ManufacturerId

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: How to get Category Name in SQL for Product?

Post by jmestep » Mon Dec 17, 2012 7:50 am

You need to find the categoryId in the ac_CatalogNodes table then get the category name from ac_Categories. In ac_CatalogNodes, for the product, the catalognodeid would be the productid with a catalognodetypeid of 1. For example, if your product id is 40 in Able's test products, the categoryid in the ac_CatalogNodes table is 3
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
david-ebt
Captain (CAPT)
Captain (CAPT)
Posts: 253
Joined: Fri Dec 31, 2010 10:12 am

Re: How to get Category Name in SQL for Product?

Post by david-ebt » Mon Dec 17, 2012 9:12 am

Try this query:

SELECT p.[Name]
,p.[Price]
,p.[MSRP]
,m.[Name] as 'Manufacturer'
,p.[Sku]
,p.[ImageUrl]
,p.[Description]
,p.[VisibilityId]
,c.[Name] as 'Category'
FROM [ac_Products] p
left JOIN ac_Manufacturers m ON p.ManufacturerId = m.ManufacturerId
left JOIN ac_CatalogNodes cn ON cn.CatalogNodeId = p.ProductId
left JOIN ac_Categories c on cn.CategoryId = c.CategoryId
where p.ProductId = 40

Note that if a product is in multiple categories you will get multiple rows for that product.
David
http://www.ecombuildertoday.com
Enhanced Reporting for AbleCommerce
Image

Mike718NY
Commodore (COMO)
Commodore (COMO)
Posts: 485
Joined: Wed Jun 18, 2008 5:24 pm

Re: How to get Category Name in SQL for Product?

Post by Mike718NY » Mon Dec 17, 2012 10:04 am

thanks . .. I 'll give it try.

Post Reply