I am using sqlserver 2008, I want to initialize and increment the variable ( @NUMTwo) at the same time, in my second part (Problem Line).
I am creating a cte request.
Is this possible, if so, please let me know.
The following is an example of an example. I hope I understand.
CREATE table
(
childProductID INT,parentProductID INT,productModel varchar(50),[Num2] VARCHAR(100)
)
DECLARE @NUMTwo INT = 0
WITH tableR AS
(
SELECT childProductID = null,parentProductID=null,productModel from Products where productid in (@a),[Num2] = convert(varchar(100), '')
UNION ALL
SELECT e.childProductID,e.parentProductID,prd.productModel FROM ProductIncludes AS e
,[Num2] = convert(varchar(100),'1.' + @NUMTwo+=1 )
INNER JOIN Products AS PRD ON e.childProductID = PRD.productID
WHERE parentProductID in (@a)
)
INSERT INTO
SELECT childProductID,parentProductID,productModel,[Num2]
END
SELECT * FROM
source
share