'Pyodbc - read output parameter of stored procedure SQL Server
I'm trying to read the output parameter of the stored procedure but I couldn't able to read it I have tried this approach referred from here I was getting this error not all arguments converted during string formatting
views.py:
@api_view(['POST'])
def FetchSuggestionAuditAgent(request):
if request.method == 'POST':
Agents = request.data.get('Agents')
sql = """\
DECLARE @out nvarchar(max);
EXEC [dbo].[sp_FetchSuggestionAuditAgent] @agents = ?, @response = @out OUTPUT;
SELECT @out AS the_output;
"""
params =(Agents, '')
print(params)
cursor = connection.cursor()
cursor.execute(sql, str(params))
rows = cursor.fetchall()
return Response({'Agents':row[0]})
Stored Procedure:
ALTER PROCEDURE [dbo].[sp_FetchSuggestionAuditAgent] --'div' ,''
@agents nvarchar(max),@response nvarchar(1000) OUTPUT
AS
BEGIN
set @agents = replace(@agents,' ', '%')
select @response = FullName from (
select FullName from tblusers where IsActive=1
union all
select FullName from tblusers where IsActive=0
and UserRole='Snowuser'
)as a
where FullName like @agents--('%'+@agents+'%')
order by FullName desc
END
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
