[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Setting a parameter value?

Posted on 2011-09-27
4
Medium Priority
?
273 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 1000 total points
ID: 36714427
0
 
LVL 9

Assisted Solution

by:mimran18
mimran18 earned 500 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 500 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

873 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