Link to home
Start Free TrialLog in
Avatar of pauldes
pauldes

asked on

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
Avatar of Aneesh
Aneesh
Flag of Canada image

pauldes,
> exec productioned.dbo.rsp_getnewidwithretval 'Distribution',Distribution_Id

the sysntax for exec is

exec ('ur dynamic code')  
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, leave my post, Angel is right
Avatar of pauldes
pauldes

ASKER

Thanks