Solved

Need help with SQL syntax error

Posted on 2008-10-16
2
244 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:lapucca
2 Comments
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 total points
ID: 22737007
Try

SET @interestChildId = parentId
0
 

Author Comment

by:lapucca
ID: 22737016
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.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question