【问题标题】:How to output json file without carriage return in column name generating json with SQL Server Management Studio 12.7如何在使用 SQL Server Management Studio 12.7 生成 json 的列名中输出不带回车的 json 文件
【发布时间】:2018-11-26 07:34:07
【问题描述】:

存储过程中bcp生成的JSON文件有问题。

列名有回车。所以 Web 服务器不理解 JSON。

像这样:

1. "leo_profit":-0.0748},{"ID":28977,"annual_profit":-0.84,"ttp":-455.8405,

2."leo_profit":-0.0748},{"ID":28977,"annual_profit":-0.84,"ttp":-455.8405,

第一个是由 SQL Server 2017 的存储过程中的 bcp 生成的,如您所见,列名“ann”和“ual_profit”之间有一个 CR。 annual_profit 是列名。

第二个是Web服务器可以理解的JSON格式。

如何使存储过程中的bcp生成列名之间没有任何CR?

【问题讨论】:

    标签: json sql-server bcp


    【解决方案1】:
    SELECT TOP 7200 
            ID, 
            CAST(annual_profit AS DECIMAL(20,2)) AS annual_profit, 
            CAST(ttp AS DECIMAL(20,4)) AS ttp, 
            tr_year, 
            tr_month, 
            tr_day, 
            tr_hour, 
            tr_min, 
            CAST(btc AS DECIMAL(20,1)) AS btc, 
            CAST(cash_rate AS DECIMAL(20,4)) AS cash_rate, 
            CAST(leo_profit AS DECIMAL(20,4)) AS leo_profit
        FROM [dbo].[Q_annual_profit_flow] 
        ORDER BY tr_date DESC 
        FOR JSON path
    

    这是另一个名为SP_Get_ANNUAL_PROFIT_FOR_JSON的存储过程

    【讨论】:

      【解决方案2】:
      DECLARE @command    VARCHAR(1000)   
      SET @command = 'BCP "EXEC mdrcoin.dbo.SP_Get_ANNUAL_PROFIT_FOR_JSON " queryout "D:\inetpub\json\SP_Get_ANNUAL_PROFIT.json" -c -T -t "|" '
      EXEC xp_cmdshell @command
      

      bcp 正在上面显示的存储过程中运行。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-02-18
        • 2012-03-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多