且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在SQL Server 2012列中查询JSON

更新时间:2023-01-29 16:14:23

老实说,这是用于存储数据的糟糕架构,可能会导致一些严重的性能问题.

Honestly, this is a terrible architecture for storing the data, and can result in some serious performance issues.

如果您确实没有控制权来更改数据库,则可以 通过使用SUBSTRING解析值来完成此操作,如下所示,但这会导致一条非常不愉快的路:>

If you truly don't have control to change the database, you can accomplish this by parsing out the value with SUBSTRING like below, but it's leading down a very unhappy path:

SELECT *
FROM tb1
JOIN tb2 on tb2.bvin = 
    SUBSTRING(
        tb1.json
        ,CHARINDEX('"bvin":"', tb1.json) + LEN('"bvin":"')
        ,CHARINDEX('"', tb1.json, CHARINDEX('"bvin":"', tb1.json) + LEN('"bvin":"')) - CHARINDEX('"bvin":"', tb1.json) - LEN('"bvin":"')
    )

可悲的是,这很容易.