Using Select statement as parameter for SPROC

I have an sproc that has parameter A(varchar(30) and parameter B(binary(8).

parameter B is a record ID in my database

If I execute
rsp_getnewidwithretval 'Distribution',0x0000000000002ED1

It works, BUT I'm trying to dynamically assign parameter B. I've tried many variations including:
exec rsp_getnewidwithretval 'Distribution',(Select Top 1 Distribution_ID from Distribution)
AND
Select Top 1 Distribution_ID from Distribution
exec productioned.dbo.rsp_getnewidwithretval 'Distribution',Distribution_Id

but end up getting:
Incorrect syntax near '('.
or
Implicit conversion from data type nvarchar to binary is not allowed. Use the CONVERT function to run this query.

HELP.....Thanks
pauldesAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
declare @b varbinary(50)
select top 1 @b = cast(Distribution_ID as varbinary(50)) from Distribution
exec rsp_getnewidwithretval 'Distribution', @b
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
pauldes,
> exec productioned.dbo.rsp_getnewidwithretval 'Distribution',Distribution_Id

the sysntax for exec is

exec ('ur dynamic code')  
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
Sorry, leave my post, Angel is right
0
 
pauldesAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.