从vs运行此查询时获取超时异常

时间:2015-01-22 07:37:32

标签: sql sql-server-2008 sql-server-2008-r2

Category

Questions

这是我的表结构我需要每个类别子类别的相关类别的计数和问题计数,其中Isparent = 1来自类别表这是我的结果表

enter image description here 这是我的代码 我的问题是它在从应用程序(VS)运行时在sql server中运行它抛出一个时间我们的错误 在哪里,我做错了帮我出去了。 提前谢谢。

DECLARE @TEMP TABLE (CategoryID INT,NAME VARCHAR(52))
INSERT INTO @TEMP SELECT CategoryID,Name FROM EC_M_CategoriesMaster    where IsParent=1  

DECLARE @TEMP1 TABLE ( CategoryID INT,cCOUNTS INT)
INSERT INTO @TEMP1 SELECT te.CategoryID,COUNT((ISNULL(te1.PCategoryID,0)))
AS Ccount from @TEMP te inner join  EC_M_CategoriesMaster te1 on te.CategoryID=te1.PCategoryID  GROUP BY te.CategoryID

DECLARE @TEMP2 TABLE (CategoryID INT,COUNTS INT )
INSERT INTO @TEMP2 SELECT CategoryID,COUNT((ISNULL(QuestionID,0)))
AS Qcount from EC_M_QuestionMaster GROUP BY CategoryID  
SELECT t1.CategoryID,t1.Name,ISNULL(t.COUNTS,0) as Qcount,ISNULL(MY.cCOUNTS,0) AS CatCount from
@TEMP2 t RIGHT OUTER JOIN   
@TEMP t1 ON t.CategoryID=t1.CategoryID
LEFT JOIN @TEMP1 MY ON  MY.CategoryID=T1.CategoryID

0 个答案:

没有答案