我正在创建一个cte查询.
这是可能的,如果是的话请告诉我.
以下是一个示例.我希望我很清楚.
CREATE table #Temptable (childProductID INT,parentProductID INT,productModel varchar(50),[Num2] VARCHAR(100))DECLARE @NUMTwo INT = 0WITH tableR AS ( -- First Part SELECT childProductID = null,parentProductID=null,productModel from Products where productID in (@a),[Num2] = convert(varchar(100),'') UNION ALL --Second Part SELECT e.childProductID,e.parentProductID,prd.productModel FROM ProductIncludes AS e,'1.' + @NUMTwo+=1 ) -- Problem line INNER JOIN Products AS PRD ON e.childProductID = PRD.productID WHERE parentProductID in (@a) )INSERT INTO #Temptable(childProductID,parentProductID,productModel,[Num2])SELECT childProductID,[Num2]END SELECT * FROM #Temptable解决方法 如果参数@NUMTwo仅用于编号行,则可以使用ROW_NUMBER()OVER(…)代替它,如下所示:
WITH tableR AS ( SELECT childProductID = NulL,parentProductID = NulL,NUMTwo = CAST('0' AS VARCHAR(10)) FROM Products WHERE productID in (@a),'') UNION ALL SELECT e.childProductID,prd.productModel,NUMTwo = '1.' + CAST( ROW_NUMBER() OVER(ORDER BY (SELECT 0)) AS VARCHAR(10)) FROM ProductIncludes AS e INNER JOIN Products AS PRD ON e.childProductID = PRD.productID WHERE parentProductID in (@a) )总结
以上是内存溢出为你收集整理的在cte query sqlserver 2008中初始化和增加变量全部内容,希望文章能够帮你解决在cte query sqlserver 2008中初始化和增加变量所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)