我有一个包含字符串的表:
Field1
150120154030
201012
我想将两个字符串行中的数据插入到这样的表中:
F1 F2 F3 F4 F5 F6
15012015 40 30 20 10 12
为此编写查询的任何帮助?
答案 0 :(得分:1)
你的问题怎么不清楚,我可以考虑这样的查询:
SELECT
MAX(IIF(Field1 = '150120154030', P1, '')) As F1,
MAX(IIF(Field1 = '150120154030', P2, '')) As F2,
MAX(IIF(Field1 = '150120154030', P3, '')) As F3,
MAX(IIF(Field1 = '201012', P1, '')) As F4,
MAX(IIF(Field1 = '201012', P2, '')) As F5,
MAX(IIF(Field1 = '201012', P3, '')) As F6
FROM (
SELECT
Field1,
MID(Field1, 1, LEN(Field1) - 4) As P1,
MID(Field1, LEN(Field1) - 3, 2) As P2,
MID(Field1, LEN(Field1) - 1, 2) As P3
FROM yourTable) DT;