Link to home
Start Free TrialLog in
Avatar of lapucca
lapucca

asked on

Need help with SQL syntax error

Hi, I'm getting sytax error for the line:
@interestChildId = parentId

Msg 102, Level 15, State 1, Procedure GetData, Line 63
Incorrect syntax near '@interestChildId'.

It's been a while since I write query.  Appreciate some help here.  Thank you.




DECLARE @interestChildId bigint;
 
Declare curApplicationRow Cursor FOR
SELECT RchChildId from NewApplication
 
Open curApplicationRow
FETCH NEXT FROM curApplicationRow
INTO @interestChildId
 
 
WHILE @@FETCH_STATUS =0  --GO THROUGH EACH RECORD
BEGIN
	SELECT dbo.ResearchInterests.Name as interestName, dbo.ResearchInterests.ParentResearchInterest_id as parentId
	from dbo.ResearchInterests
	WHERE dbo.ResearchInterests.Id = @interestChildId
 
	WHILE(parentId <> NULL)--USE THE PARENTID TO TRAVERSE TO ITS PARENT NODE UNTIL REACHES ROOT NODE
	BEGIN
		@interestChildId = parentId
		SELECT dbo.ResearchInterests.Name, dbo.ResearchInterests.ParentResearchInterest_id as parentId
		from dbo.ResearchInterests
		WHERE dbo.ResearchInterests.Id = @interestChildId
	END
 
	FETCH NEXT FROM curApplicationRow
	INTO @interestChildId
END

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lapucca
lapucca

ASKER

Yap!  That did the trick.  It's been a few years since I write queries.  I know what I want just can't remember all the syntax.  Thanks.