2013-05-05 46 views
1

你好,我有我收到一個初學者問題得到一個對象的所有條目

以下statment

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

我認爲你不需要把變量記錄在變量中,因爲你可以直接在另一個表上插入記錄。

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] 
相關問題