Solved

Setting a parameter value?

Posted on 2011-09-27
4
262 Views
Last Modified: 2012-05-12
How do I set a parameter to the result of an EXECUTE?
I tried this but got an error.
Set @Y  = EXECUTE (@X)

(the value of @X is a valid select statement)
So that :
Set @X = 'Select top(1) item from dbo.sales where ....'
EXECUTE (@X)
returns a value.
But I need the value assigned to @Y
Please help!
0
Comment
Question by:n2dweb
4 Comments
 
LVL 15

Accepted Solution

by:
Eyal earned 250 total points
ID: 36714427
0
 
LVL 9

Assisted Solution

by:mimran18
mimran18 earned 125 total points
ID: 36714560
Hi,
   Here is the sample.

Declare @X as nvarchar(100)
Declare @Item int

Set @X='Select top 1 @Item=[Item] from [Table Name]'
Exec sp_executesql @X,N'@Item int output',@Item output
Select @Item

0
 
LVL 9

Assisted Solution

by:sachinpatil10d
sachinpatil10d earned 125 total points
ID: 36714569
Try this
DECLARE @X nvarchar(500);
DECLARE @Y varchar(30);
SET @X = N'Select top(1) @out = item from dbo.sales';
exec sp_executesql @X, N'@out varchar(30) OUTPUT', @out=@Y OUTPUT;
SELECT @Y;

Open in new window

0
 
LVL 1

Author Closing Comment

by:n2dweb
ID: 36714676
Part of my issue was that I needed to use nVARCHAR and not VARCHAR
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

930 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now