Solved

Need help with SQL syntax error

Posted on 2008-10-16
2
243 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

Suggested Solutions

Title # Comments Views Activity
Unable to save view in SSMS 21 70
get column names from table in vb.net 8 30
Get number of Files in Directory and Sub Directories 2 42
ServiceCenter IR Query Expressions 1 23
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 …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

803 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