lapucca
asked on
Can I select a field value into a @variable so I can use it in my next Insert statement?
Hi, I'm currently getting error in the following code for 'interestName'. It doesn't like me using it in the Insert statement. Do I need to select into a @variable? What's the syntax like? Thank you.
Msg 128, Level 15, State 1, Procedure GetData, Line 85
The name "interestName" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
Msg 128, Level 15, State 1, Procedure GetData, Line 85
The name "interestName" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
SELECT dbo.ResearchInterests.Name as interestName, dbo.ResearchInterests.ParentResearchInterest_id as parentId
from dbo.ResearchInterests
WHERE dbo.ResearchInterests.Id = @interestChildId
INSERT INTO [CtsiMembershipProduction].[dbo].[Interest]
([Name])
VALUES
(interestName)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
WHILE @@FETCH_STATUS =0 --GO THROUGH EACH RECORD
BEGIN
--The following select will get us the 1st child id for Rsch interest
SELECT dbo.ResearchInterests.Name
from dbo.ResearchInterests
WHERE dbo.ResearchInterests.Id = @interestChildId
INSERT INTO [CtsiMembershipProduction]
VALUES
(interestName)
WHILE(parentId <> NULL)--USE THE PARENTID TO TRAVERSE TO ITS PARENT NODE UNTIL REACHES ROOT NODE
BEGIN
set @interestChildId = parentId
SELECT dbo.ResearchInterests.Name
from dbo.ResearchInterests
WHERE dbo.ResearchInterests.Id = @interestChildId
END
FETCH NEXT FROM curApplicationRow
INTO @interestChildId
END