pymssql calling SQL Server stored procedure with output parameters

Source: Internet
Author: User

Tags: TCO tab MSSQL process DIV varchar ParentID Play MSS

pymssql calling SQL Server stored procedure with output parameters

Directly on the code

defapi_adddept (): Data=json.loads (Request.get_data ()) UserData={} with Usedatabasesqlserver () as Cursor:msg=cursor.callproc ('[AppData]. [dbo]. [Fyit_adddept]', (data["Parentdept_add"],data["Deptname_add"],1, Pymssql.output (str), Pymssql.output (str))) userdata['Result_code']=msg[3] userdata['result_msg']=msg[4]                #sql= ' DECLARE @return_value int, @result_code nvarchar (1024x768), @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]) # Breakresp=jsonify (userdata) Resp.status_code= 200returnResp

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

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: