Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using Select statement as parameter for SPROC

Posted on 2006-05-09
4
Medium Priority
?
299 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:pauldes
  • 2
4 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 16642180
pauldes,
> exec productioned.dbo.rsp_getnewidwithretval 'Distribution',Distribution_Id

the sysntax for exec is

exec ('ur dynamic code')  
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 16642181
declare @b varbinary(50)
select top 1 @b = cast(Distribution_ID as varbinary(50)) from Distribution
exec rsp_getnewidwithretval 'Distribution', @b
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 16642199
Sorry, leave my post, Angel is right
0
 

Author Comment

by:pauldes
ID: 16642636
Thanks
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

810 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