简体   繁体   English

SQL-从第二列插入行值(作为列数据插入新表)

[英]SQL - insert row values from second column ( to new table as column data)

While having the result set: 设置结果时:

Name        Values

PRODUCT                         FILLER888
LOT_NUMBER                  CG 00063 0
SHIFT_SUPERVISOR        covaliu l
KGH_ALL_SET 90
KGH_ALL_REAL    133.183883666992
KGH_F1_SET  90
KGH_F1_REAL 133.183883666992
K_F1    33
SCREW_RPM_SET   400
SCREW_RPM_REAL  399.452606201172
TORQUE  19.6692142486572
CURRENT 71.0029983520508
KW_KG   0.0553370267152786
KW  7.36999988555908
MELT_PRESSURE   0
MELT_TEMPERATURE    140
PV1 141
SP1 140
PV2 160
SP2 160
PV3 160
SP3 160
PV4 160
SP4 160
PV5 160
SP5 160
PV6 150
SP6 150
PV7 150
SP7 150
PV8 154
SP8 150
PV9 150
SP9 150
PV10    160
SP10    160
PV11    180
SP11    180

I would like into a second table which is defined as the rows of the 1st: 我想进入第二个表,该表定义为第一行:

CREATE TABLE #ZSK402temp 
(
 PRODUCT varchar(25),
LOT_NUMBER varchar(25),
SHIFT_SUPERVISOR varchar(25), 
KGH_ALL_SET decimal, 
KGH_ALL_REAL decimal, 
KGH_F1_SET decimal, 
KGH_F1_REAL decimal, 
K_F1 decimal, 
SCREW_RPM_SET decimal, 
SCREW_RPM_REAL decimal, 
TORQUE decimal, 
[CURRENT] decimal, 
KW_KG  decimal, 
KW decimal, 
MELT_PRESSURE decimal, 
MELT_TEMPERATURE decimal, 
PV1 decimal, 
SP1 decimal, 
PV2 decimal, 
SP2 decimal, 
PV3 decimal, 
SP3 decimal, 
PV4 decimal, 
SP4 decimal, 
PV5 decimal, 
SP5 decimal, 
PV6 decimal, 
SP6 decimal, 
PV7 decimal, 
SP7 decimal, 
PV8 decimal, 
SP8 decimal, 
PV9 decimal, 
SP9 decimal, 
PV10 decimal, 
SP10 decimal, 
PV11 decimal, 
SP11 decimal
 )

To insert the values from the 1st table as column data in the second table. 将第一张表中的值作为列数据插入第二张表中。

Any help is kindly apreciated. 任何帮助,我们都感激不尽。

Look up some examples using SQL's PIVOT function. 使用SQL的PIVOT函数查找一些示例。 This will swap rows into columns to match the new table. 这会将行交换为列以匹配新表。

Link: http://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspx 链接: http//technet.microsoft.com/zh-cn/library/ms177410(v = sql.105).aspx

Insert into table2 (SELECT * FROM table1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果 2 列值不存在,则在 SQL 表中插入新行数据 - Insert new row of data in SQL table if the 2 column values do not exist SQL SERVER为现有表的每一行插入新列值 - SQL SERVER Insert New Column Values for every row of existing table SQL 从表的开头向新列插入新值 - SQL insert new values into new column from the beginning of table 将具有来自 python 列表的值的新列插入到现有 sql 表中 - Insert new column with values from a python list into an existing sql table 在SQL插入中,在第二列中写入新行的已分配ID - On SQL insert, write the new row's assigned ID in a second column 我想将第一个SQL表中的数据插入第二个SQL表中,而第二个表中不存在额外的列 - I want to insert data from first SQL table into second one also with an extra column not present in the second one sql,将从第一个表获得的行值与没有循环的第二个表的列名匹配 - sql, matching row values obtained from first table to the column names of second table without loop SQL将新行插入到现有表中,更改除一列外的所有列 - SQL Insert a new row into an existing table changing all but one column 将1到2的2列值合并到新表的新行中-SQL - Combine 2 column values in 1 to many into new row in new table - SQL 使用表中的值更新新的SQL列 - Updating a new SQL column with values from the table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM