Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Setting a parameter value?

Posted on 2011-09-27
4
Medium Priority
?
269 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

609 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