I am wanting to use an out variable, but I need to perform calculations as well. Any way I write my query I keep getting this error:
Msg 141, Level 15, State 1, Line 1
A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.
Here is my DDL
Declare @SQL nvarchar(MAX), @stat float
Create Table PPerformance
(
name varchar(500)
,attempts int
,success int
)
Insert Into PPerformance (name, attempts, success) Values
('Bob', '22', '10')
,('Red', '14', '12')
And this is my query syntax
Set @SQL = 'Select name, @stat = attempts/success FROM PPerformance where name = Bob'
EXECUTE sp_executesql @SQL, N'@stat float OUTPUT', @stat OUTPUT;
Select @stat As Stat
Drop Table PPerformance
What do I need to change so that I can store the value from the equation in the variable @stat