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 |
|
craigmacca
Posting Yak Master
142 Posts |
Posted - 2008-02-20 : 15:53:35
|
| Hi i have a query which i cant get to work,i need to display categories and sub categoriesCategory 1SubCat1SubCat2Category 2SubCat1SubCat2but i am actually getingCategory 1SubCat1Category 1SubCat2Category 2SubCat1Category 2SubCat2any ideas what i need to do to this query?select CT.Cat_ID, CT.Cat_Name, ST.SubCat_Name, ST.SubCat_IDfrom dbo.Category_Table CTLEFT JOIN dbo.SubCategory_Table ST ON ST.SubCat_Cat_ID = CT.Cat_ID |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-02-20 : 16:06:43
|
[code]SELECT COALESCE(d.SubCat_ID, d.Cat_ID) AS CatID, COALESCE(d.SubCat_Name, d.Cat_Name) AS CatNameFROM ( SELECT ct.Cat_ID, ct.Cat_Name, st.SubCat_Name, st.SubCat_ID FROM dbo.Category_Table AS ct LEFT JOIN dbo.SubCategory_Table AS st ON st.SubCat_Cat_ID = ct.Cat_ID UNION SELECT Cat_ID, Cat_Name, NULL, NULL FROM dbo.Category_Table ) AS dORDER BY d.Cat_Name, d.Cat_ID, d.SubCat_Name[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
craigmacca
Posting Yak Master
142 Posts |
Posted - 2008-02-20 : 16:28:22
|
| thanks tried adding that to my sp but i get Msg 156, Level 15, State 1, Procedure GetCategories, Line 12Incorrect syntax near the keyword 'AS'.Msg 156, Level 15, State 1, Procedure GetCategories, Line 26Incorrect syntax near the keyword 'NULL'. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-02-20 : 16:39:09
|
See edited response. I was missing a right paranthesis and a comma. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
craigmacca
Posting Yak Master
142 Posts |
Posted - 2008-02-24 : 14:26:55
|
| ok i can see what you have done which is good but..i need the Category to be named different to the SubCategory.i need to be able to display in my webpage as below so when a user clicks on the category the sub categories drop down.CategorySubCategorySubCategorySubCategoryCategorySubCategorySubCategorySubCategoryCategorySubCategorySubCategorySubCategory |
 |
|
|
|
|
|
|
|