看到Json表达式, 在某些特殊情况下直接存json值。  下面取json表达式某项的值。

/*
取Json表达式值
参数: @code,@json
返回: @code 对应的值
eg.
@json='{"free":30,"first":1,"first fee":10,"per":30,"per fee":1.5}'
select dbo.UFJson('per',@json)
*/
create function [UFJson]
(
@code varchar(100),
@json nvarchar(2000))
returns nvarchar(500)
AS
BEGIN
    declare @codeindex as int
    declare @valueindex as int
    declare @endindex as int

set @codeindex = charindex(@code,@json)
    --没有找到code项
    if (@codeindex = 0) return ''
    
    set @valueindex = charindex(':',@json,@codeindex)
    set @endindex = charindex(',',@json,@codeindex)    
    
    if (@endindex = 0) set @endindex = charindex('}',@json,@codeindex)

--格式不对 return ''
    if (@valueindex = 0 or @endindex = 0) return ''
        
    --正常返回
    return substring(@json,@valueindex+1,@endindex-@valueindex-1)
END

GO

转载于:https://www.cnblogs.com/pnglooog/p/3262026.html

sql server Json表达式解析函数相关推荐

  1. SQL Server JSON:性能手册

    目录 介绍 1. 数据类型 2. 存储 3. 压缩/解压 4. 压缩 5. 列存储 6. 创建JSON 7.检查JSON 8. JSONValue 9. OpenJson 10. 字符串拆分 11.  ...

  2. sql与nosql_SQL Server JSON函数:NoSQL与关系世界之间的桥梁

    sql与nosql In this article, we will explain what JSON is, what are the SQL Server JSON functions intr ...

  3. SQL Server 2016中的本机JSON支持

    With the introduction of SQL Server 2016, Microsoft introduced many new features which had taken SQL ...

  4. SQL server中的类似Java的三目表达式及游标使用

    运行环境:SQL server 2008R2 表达式:SELECT (CASE WHEN 1=1 THEN 'True' ELSE 'False' END) BEGINDECLARE @status ...

  5. 利用T-SQL动态定义重复SQL Server数据库表行

    介绍 (Introduction) Lever T-SQL to handle duplicate rows in SQL Server database tables article highlig ...

  6. Oracle 9i与MS SQL Server 2000之比较连载五.zz

    http://kb.cnblogs.com/a/1153156 Oracle 9i与MS SQL Server 2000之比较连载五 2008-04-14 18:13 四.Oracle中新的数据库对象 ...

  7. SQL Server 2016 JSON原生支持实例说明

    原文:SQL Server 2016 JSON原生支持实例说明 背景 Microsoft SQL Server 对于数据平台的开发者来说越来越友好.比如已经原生支持XML很多年了,在这个趋势下,如今也 ...

  8. modify sql_在SQL Server中使用JSON_MODIFY()修改JSON数据

    modify sql This article explores JSON_MODIFY() function to modify JSON Data in the SQL Server. 本文探讨了 ...

  9. 在SQL Server中将数据导出为XML和Json

    BCP "SELECT DEPT_CODE,PARENTCODE FROM longshinewebhr.dbo.b01 where PARENTCODE like '10201%' FOR ...

最新文章

  1. SetWindowRgn注意点
  2. android应用中插入admob广告
  3. 【Python爬虫】写个爬虫爬取自己的博客,可以刷访问量
  4. 振动系统零频率和重频率问题探讨
  5. MySQL之Procedure(存储过程)和Function(函数)
  6. android 条码扫描控件,Android Zxing条码扫描自定义控件(附代码)
  7. SpringCloud Config 本地配置
  8. erlang在mac上安装
  9. c语言怎么求一个数的所有因数,【代码】求一个数的因数和、求优化、顺便也供新人参考算法...
  10. Android Design 1: Back键和Up键在App导航中的表现
  11. 常用工具类(初级中的初级)
  12. 管道|符与xargs命令
  13. 趣味项目—MyQQ机器人(二)关于python的pandas根据索引读写指定数据的方法实现签到功能
  14. 数据结构之冒泡排序的两个优化细节
  15. 55-将单链表原地逆置(三种方法)
  16. 小米3的卡槽,卡住了
  17. 关闭启动最新Photoshop 2021自动同步预设提示方法(临时)
  18. 在xml中定义excel的sheet_XML和Excel
  19. 图像风格迁移cvpr2020_CVPR 2020 论文大盘点-文本图像篇
  20. 【计组】字长、数据总线、地址总线

热门文章

  1. 方差、标准差、均方差、均方误差理解
  2. python人脸识别、人脸关键点检测、性别检测
  3. MySQL下载与MySQL安装图解(MySQL5.7与MySQL8.0)
  4. Ruby种的特殊变量
  5. react学习笔记(序)
  6. Angular2响应式表单
  7. 重读《从菜鸟到测试架构师》-- 单元测试测点啥
  8. Openjudge2729 Blah数集(单调队列)
  9. Linq to sql与EF零碎知识点总结
  10. I Hate It(线段树基础)