目的:统一接口,当数据结构发生变化时,前后端业务接口不发生变化,由业务具体解析结构。
规则:确定的接口用参数表(多行提交),不确定的参数用XML
?
- DECLARE @r TABLE
- ????(
- ??????HardwareNo INT ,
- ??????emvno INT ,
- ??????DATA XML
- ????)
- INSERT
INTO @r - VALUES ( 1, 1,
- ??????????‘<d><k>meter</k><v>1</v></d><d><k>run</k><v>100</v></d><d><k>work</k><v>80</v></d><d><k>dead</k><v>20</v></d>‘ ),
- ????????( 2, 1,
- ??????????‘<d><k>meter</k><v>21</v></d><d><k>run</k><v>100</v></d><d><k>work</k><v>80</v></d><d><k>dead</k><v>20</v></d>‘ ),
- ????????( 3, 1,
- ??????????‘<d><k>meter</k><v>31</v></d><d><k>run</k><v>100</v></d><d><k>work</k><v>80</v></d><d><k>dead</k><v>20</v></d><d><k>good</k><v>210</v></d>‘ )
- ?
- ?
- SELECT *
- FROM @r
- ?
- ?
- DECLARE @xml XML
- SELECT @xml = data
- FROM @r
- SELECT T.c.value(‘k[1]‘, ‘varchar(20)‘) k ,
- ????????T.c.value(‘v[1]‘, ‘varchar(20)‘) v
- FROM @xml.nodes(‘/d‘) T ( c )
- ?
- ?
- ?
- SELECT HardwareNo ,
- ????????T.c.value(‘k[1]‘, ‘varchar(20)‘) k ,
- ????????T.c.value(‘v[1]‘, ‘varchar(20)‘) v
- FROM @r
- ????????CROSS APPLY data.nodes(‘/d‘) AS T ( c )
?
输出结果:
?
- (3 行受影响)
- HardwareNo emvno DATA
- 1 1 <d><k>meter</k><v>1</v></d><d><k>run</k><v>100</v></d><d><k>work</k><v>80</v></d><d><k>dead</k><v>20</v></d>
- 2 1 <d><k>meter</k><v>21</v></d><d><k>run</k><v>100</v></d><d><k>work</k><v>80</v></d><d><k>dead</k><v>20</v></d>
- 3 1 <d><k>meter</k><v>31</v></d><d><k>run</k><v>100</v></d><d><k>work</k><v>80</v></d><d><k>dead</k><v>20</v></d><d><k>good</k><v>210</v></d>
- ?
- (3 行受影响)
- ?
- k v
- -------------------- --------------------
- meter 31
- run 100
- work 80
- dead 20
- good 210
- ?
- (5 行受影响)
- ?
- HardwareNo k v
- ----------- -------------------- --------------------
- 1 meter 1
- 1 run 100
- 1 work 80
- 1 dead 20
- 2 meter 21
- 2 run 100
- 2 work 80
- 2 dead 20
- 3 meter 31
- 3 run 100
- 3 work 80
- 3 dead 20
- 3 good 210
- ?
- (13 行受影响)
?
?
?
?
?
?
时间: 2024-10-25 03:33:13