VBA POST calls Web API to format SQL statements

Source: Internet
Author: User
Tags http post

Work encountered a scene, need to use VBA to re-beautiful SQL statement format, originally wanted to directly call the local Sqlworkbench tool to achieve this function, but can not find the command parameters, cannot be directly called by VBA, forget.

Find the API that can call the website directly with VBA call HTTP POST can be implemented.

Web API Description:

Https://github.com/sqlparser/sql-pretty-printer/wiki/SQL-FaaS-API-manual

The required parameters are Rqst_input_sql, and the SQL statements with conversions are passed in.

Response the parameters of attention inside, rspn_output_fmt the SQL statement after the conversion.

The VBA function code is as follows:

FunctionCallsqlformat (ByValSql as String)  DimhttpSetHTTP =CreateObject("Microsoft.XMLHTTP") http. Open"POST","http://www.gudusoft.com/format.php",FalseHttp.setrequestheader"Content-type","application/x-www-form-urlencoded"Http.send"rqst_input_sql="&SQLIfhttp. Status = $  ThenResp_text=Http.responsetext Istart=InStr(Resp_text,"Rspn_formatted_sql") Iend=InStr(Resp_text,"}") Callsqlformat=Replace(Mid(Resp_text, Istart + -+2+1, Iend-istart- A),"\ n", vblf)ElseCallsqlformat=SQLEnd IfEnd Function

VBA POST calls Web API to format SQL statements

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.