Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2008 从表_a的不同行中选择多个值,并将其放入表_b的一个新行中_Sql Server 2008 - Fatal编程技术网

Sql server 2008 从表_a的不同行中选择多个值,并将其放入表_b的一个新行中

Sql server 2008 从表_a的不同行中选择多个值,并将其放入表_b的一个新行中,sql-server-2008,Sql Server 2008,我有一张如下表: 'table_a' Type | Value -----+------------ 000 | 100020003 001 | 004 002 | 5000600070008 'table_b' ---+---+---+--- 1 | 2 | 3 | 4 ETC... 我需要得到一个结果集,如下所示: 'table_a' Type | Value -----+------------ 000 | 100020003 001 | 004 002 |

我有一张如下表:

'table_a'
Type | Value
-----+------------
000  | 100020003
001  | 004
002  | 5000600070008
'table_b' 
 ---+---+---+---
 1 | 2 | 3 | 4     ETC...
我需要得到一个结果集,如下所示:

'table_a'
Type | Value
-----+------------
000  | 100020003
001  | 004
002  | 5000600070008
'table_b' 
 ---+---+---+---
 1 | 2 | 3 | 4     ETC...
我已经使用子字符串来拉1、2和3,其中type=000。现在,我需要对类型001和002执行相同的操作,但是如何将它们连接在一起以在“table_b”中创建一行呢

到目前为止,我使用了下面的填充1、2和3,但我不知道如何从其余行中选择数据

SELECT SUBSTRING(Value,1,1) AS val_1
       SUBSTRING(Value,5,1) AS val_2
       SUBSTRING(Value,9,1) AS val_3
  FROM table_a
 WHERE type = 000
下一个查询如下所示: 选择子字符串(值3,1)作为值4 来自表a 其中type=001

如您所见,我不能使用union,因为我在每个select语句中选择的项目数不同

我从中获取的数据并非如此统一,但希望这能传达出我需要正确做的事情。我非常感谢任何帮助

SELECT SUBSTRING(Value,1,1) || "val_1",
       SUBSTRING(Value,5,1) || "val_2",
       SUBSTRING(Value,9,1) || "val_3",
  FROM table_a
 WHERE type = 000