convert query output into json format in sql server

后端 未结 3 471
我在风中等你
我在风中等你 2021-01-24 13:49

I want to display the below query output into JSON Format(Required output format)

select ApplicationID ApplicationID ,Roleid Roles from UserRoles where userid=1         


        
3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-24 14:01

    If you are using SQL Server 2016+, you can use FOR JSON statement

    SELECT
        ApplicationID ApplicationID,
        Roleid Roles 
    FROM UserRoles 
    WHERE userid = 11 AND applicationid IS NOT NULL
    FOR JSON AUTO
    

    Take a look into this: Format Query Results as JSON with FOR JSON

提交回复
热议问题