pymssql calling SQL Server stored procedure with output parameters

Source: Internet
Author: User

pymssql calling SQL Server stored procedure with output parameters

Directly on the code

defapi_adddept (): 

def api_adddept():
    data = json.loads(request.get_data())
    with UseDataBaseSQLServer() as cursor:

        msg=cursor.callproc(‘[AppData].[dbo].[Fyit_AddDept]‘, (data["parentdept_add"],data["deptname_add"],1,pymssql.output(str),pymssql.output(str)))
        # sql=‘DECLARE @return_value int,@result_code nvarchar(1024),@result_msg nvarchar(1024);‘\
        #     ‘EXEC @return_value = [AppData].[dbo].[Fyit_AddDept] @parentid = {0},@dept = N\‘{1}\‘,@display = 1,@result_code = @result_code OUTPUT,@result_msg = @result_msg OUTPUT;‘\
        #     ‘SELECT    @result_code as N\‘@result_code\‘,@result_msg as N\‘@result_msg\‘,@return_value as N\‘Return Value\‘;‘

        # cursor.execute(sql.format(data["parentdept_add"],data["deptname_add"]))  
        # result = cursor.fetchone()  

        # while result:
        #     userdata[‘resultcode‘]=str(result[0])
        #     userdata[‘resultmsg‘]=result[0]
        #     userdata[‘returnvalue‘]=str(result[2])
        #     break

    resp = jsonify(userdata)
    resp.status_code = 200
    return resp

Both of them are feasible.

The first kind is simple and convenient. The second is to spell the SQL yourself.

Pymssql calls SQL Server stored procedure with output parameters

Related Article

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.