Set sql variable via select

I am trying to execute a store procedure.  When I place the results of the query in it will run, however trying to set the variable in the execute statement I get .  
Incorrect syntax near the keyword 'From'.

I'm not sure what the issue is please help.

select PRJG_RecordID From ProjectGroup where PRJG_ProjectID ='4360'

EXEC      [dbo].[Ideal_ProjectCostReport]
            @ParentProjectRecordID = PRJG_RecordID From ProjectGroup where PRJG_ProjectID ='4360'
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Leo TorresSQL DeveloperCommented:
Declare @ID as int  
select @ID = PRJG_RecordID From ProjectGroup 
where PRJG_ProjectID ='4360'

EXEC  [dbo].[Ideal_ProjectCostReport]
            @ParentProjectRecordID = @ID 

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Deepak ChauhanSQL Server DBACommented:
You can not execute stored procedure like this.  You have to declare one more variable accepting the value.
like @PRJG_ProjectID

EXEC      [dbo].[Ideal_ProjectCostReport]
             @ParentProjectRecordID = <PRJG_RecordID> any int value,
             @PRJG_ProjectID ='4360'

if table ProjectGroup is using in this SP.

can you share your stored procedure script we can suggest you.
Jim HornMicrosoft SQL Server Data DudeCommented:
A scalar function can be set to a single value..
SELECT @something = dbo.fn_whatever('Sally') 

Open in new window

If by 'Executing a SP' you mean pass a variable as a parameter, then the above is correct.
If by 'Executing a SP' you mean execute the SP and set the resulting single value into a parameter, then SP's return a set, so you'll have to handle it as such..

CREATE TABLE #tmp (no int) 

INSERT INTO #tmp (no) 
exec sp_whatever ('Sally')  -- I'm a little fuzzy on what your needs are here

SELECT @no = no FROM #tmp WHERE-- ??

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.