获取对象中的所有条目

时间:2013-05-05 11:29:02

标签: sql sql-server

您好我有一个初学者问题

我收到了以下声明

SELECT * INTO #tmp_GridResults_1
FROM (
SELECT N'1333010121' AS [PcbID], N'2012-03-29 10:35:21.067' AS [TimeDone], N'5011' AS [McID], N'1' AS [CountPCB], N'0' AS [DeviceID], N'' AS [Program], N'1' AS [CycleTime], N'0' AS [NumComp], N'1' AS [NumBlocks], N'0' AS [NumErrors], N'' AS [OrderNo], NULL AS [Operation], N'1' AS [Lane], N'0' AS [SerializedID] UNION ALL
SELECT N'1333010148' AS [PcbID], N'2012-03-29 10:35:48.943' AS [TimeDone], N'5012' AS [McID], N'1' AS [CountPCB], N'0' AS [DeviceID], N'' AS [Program], N'1690' AS [CycleTime], N'179' AS [NumComp], N'1' AS [NumBlocks], N'0' AS [NumErrors], N'' AS [OrderNo], NULL AS [Operation], N'1' AS [Lane], N'0' AS [SerializedID] UNION ALL
SELECT N'1333010156' AS [PcbID], N'2012-03-29 10:35:56.177' AS [TimeDone], N'201' AS [McID], N'1' AS [CountPCB], N'0' AS [DeviceID], N'' AS [Program], N'263' AS [CycleTime], N'16' AS [NumComp], N'1' AS [NumBlocks], N'0' AS [NumErrors], N'' AS [OrderNo], NULL AS [Operation], N'1' AS [Lane], N'0' AS [SerializedID] UNION ALL
SELECT N'1333017866' AS [PcbID], N'2012-03-29 12:44:26.903' AS [TimeDone], N'5011' AS [McID], N'148' AS [CountPCB], N'0' AS [DeviceID], N'' AS [Program], N'1' AS [CycleTime], N'0' AS [NumComp], N'1' AS [NumBlocks], N'0' AS [NumErrors], N'' AS [OrderNo], NULL AS [Operation], N'1' AS [Lane], N'0' AS [SerializedID] ) t;
SELECT [PcbID], [TimeDone], [McID], [CountPCB], [DeviceID], [Program], [CycleTime], [NumComp], [NumBlocks], [NumErrors], [OrderNo], [Operation], [Lane], [SerializedID]
FROM #tmp_GridResults_1

我现在如何处理#tmp_GridResults_1中的所有内容并将其插入某个表格?

1 个答案:

答案 0 :(得分:1)

我认为您不需要将记录存储在变量中,因为您可以直接在另一个表中插入记录。

INSERT INTO tableName([PcbID], [TimeDone], [McID], [CountPCB], [DeviceID], [Program], [CycleTime], [NumComp], [NumBlocks], [NumErrors], [OrderNo], [Operation], [Lane], [SerializedID])
SELECT N'1333010121' AS [PcbID], N'2012-03-29 10:35:21.067' AS [TimeDone], N'5011' AS [McID], N'1' AS [CountPCB], N'0' AS [DeviceID], N'' AS [Program], N'1' AS [CycleTime], N'0' AS [NumComp], N'1' AS [NumBlocks], N'0' AS [NumErrors], N'' AS [OrderNo], NULL AS [Operation], N'1' AS [Lane], N'0' AS [SerializedID] UNION ALL
SELECT N'1333010148' AS [PcbID], N'2012-03-29 10:35:48.943' AS [TimeDone], N'5012' AS [McID], N'1' AS [CountPCB], N'0' AS [DeviceID], N'' AS [Program], N'1690' AS [CycleTime], N'179' AS [NumComp], N'1' AS [NumBlocks], N'0' AS [NumErrors], N'' AS [OrderNo], NULL AS [Operation], N'1' AS [Lane], N'0' AS [SerializedID] UNION ALL
SELECT N'1333010156' AS [PcbID], N'2012-03-29 10:35:56.177' AS [TimeDone], N'201' AS [McID], N'1' AS [CountPCB], N'0' AS [DeviceID], N'' AS [Program], N'263' AS [CycleTime], N'16' AS [NumComp], N'1' AS [NumBlocks], N'0' AS [NumErrors], N'' AS [OrderNo], NULL AS [Operation], N'1' AS [Lane], N'0' AS [SerializedID] UNION ALL
SELECT N'1333017866' AS [PcbID], N'2012-03-29 12:44:26.903' AS [TimeDone], N'5011' AS [McID], N'148' AS [CountPCB], N'0' AS [DeviceID], N'' AS [Program], N'1' AS [CycleTime], N'0' AS [NumComp], N'1' AS [NumBlocks], N'0' AS [NumErrors], N'' AS [OrderNo], NULL AS [Operation], N'1' AS [Lane], N'0' AS [SerializedID]