'How to get the output parameter as the response in python
I'm trying to get the list of user's based whose name starts based on the typing the name from the SQL database.
In SQL there is an output parameter in which I want to return as API response. Whenever I type the name 'R' it just returning only one character in the output but I want to return the entire name
views.py:
@api_view(['POST'])
def FetchSuggestionAuditAgent(request):
if request.method =='POST':
agents = request.data.get('Agents')
sql = """\
DECLARE @response NVARCHAR;
EXEC dbo.FetchSuggestionAuditAgent @agents = %s, @response = @response OUTPUT;
SELECT @response AS out_value;
"""
params = (agents,)
cursor = connection.cursor()
cursor.execute(sql, params)
result_set = cursor.fetchall()
print(result_set)
for row in result_set:
agents = row[0]
return Response({'Agents':agents})
SQL SP:
ALTER PROCEDURE [dbo].[sp_FetchSuggestionAuditAgent] -- 'apolonia ',''
@agents nvarchar(max),@response nvarchar(1000) OUTPUT
AS
BEGIN
set @agents = LTRIM(RTRIM(@agents))
select top 1 @response = FullName from tblusers where FullName like '%'+@agents+'%'
and isactive =1 and IsDeleted = 0
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 |
---|