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 |
|
esambath
Yak Posting Veteran
89 Posts |
Posted - 2009-05-25 : 05:25:09
|
| Hi Guys,Please help this oneI have two table LP_Category and LP_ExpertationCatId Name Parentid Status 1 Sports 0 1 2 Test 0 1 3 Music 0 1 4 Football 1 1 5 Vollyball 1 1ExpertId UserId,CatId,Degree,Experience,Qualifications 1 3 1 BE 0 student 2 4 3 BE 0 student 3 5 3 BE 0 student We want display the record Category(count of Experts) + Sports(1) + Music(2) + Test(0)This is my test queryselect CatId,ParentID,(Name +'('+ (select count(*) FROM LP_Expertation WHERE sc.CatId=CatId) +')'+) CategoryName FROM LP_Category sc where parentID=0RegardsSambath kumar |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-05-25 : 05:37:33
|
[code]SELECT c.Name + '(' + CAST(COUNT(e.CatID) AS VARCHAR(12)) + ')'FROM LP_Category AS cLEFT JOIN LP_Expertation AS e ON e.CatID = c.CatIDWHERE c.ParentID = 0GROUP BY c.Name[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-05-25 : 05:38:17
|
| select c.catid,c.parentid,c.name + ' ( '+cast(ISNULL(cnt,0) as varchar(12))+' )'from @LP_Category cleft join (select catid, count(catid)as cnt from @LP_Expertation group by catid) e on c.catid= e.catidwhere c.parentid = 0 |
 |
|
|
esambath
Yak Posting Veteran
89 Posts |
Posted - 2009-05-25 : 07:39:16
|
dear Peso,Thanks for your time.The query is working in our code thank youRegardssambathquote: Originally posted by Peso
SELECT c.Name + '(' + CAST(COUNT(e.CatID) AS VARCHAR(12)) + ')'FROM LP_Category AS cLEFT JOIN LP_Expertation AS e ON e.CatID = c.CatIDWHERE c.ParentID = 0GROUP BY c.Name E 12°55'05.63"N 56°04'39.26"
|
 |
|
|
|
|
|