troubleshooting Question

issuse obtaining output with sp_executesql

Avatar of Stacey Fontenot
Stacey Fontenot asked on
Microsoft SQL Server
2 Comments1 Solution131 ViewsLast Modified:
I am building a stored procedure calls a scalar-valued function that I created.  Example
dbo.retun_alpha( column name, parameter) ,  I have got to the point where I am trying to insert a value in the parameter section based on a table  but am having issue get the value 01  into the function)
I am trying to use SP_ECECUTESQL   below is the code

DECLARE @SQLString nvarchar(max);  
DECLARE @Parm nvarchar(max);
DECLARE @Parm1 nvarchar(max);
declare @args varchar(max);
set @Parm =  'P'+ cast( @I4 as varchar(10))+' from FROM M_TABLE_VALIDATION_RULES WHERE TABLE_VALIDATION_RULES_ID = ' + cast( @TABLE_VALIDATION_RULES_ID  as varchar(max)) + ')';                                                      
set @Parm1 = N'@Value nvarchar(max) OUTPUT'
set @SQLString =  '(SELECT @Value = ' + @Parm
EXEC sp_executesql @SQLString, @Parm1, @Value OUTPUT
set @args = @Value

I am getting

Msg 137, Level 15, State 2, Procedure DATA_CLEANSE, Line 110 [Batch Start Line 7]
Must declare the scalar variable "@Value".
Stacey Fontenot

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros