我確定這很簡單,我會踢我自己,當我發現,但我一直坐在這個 問題的最後一個小時,我感到惱火,任何人都可以幫助我。SQL返回多個值
所以我想輸入一個DeviceId和ConfigurationId列的值是設備表和配置表中的主鍵。是的,這就是所有問題。
我嘗試使用(SELECT ID FROM DeviceId)
但是,隨着錯誤出現,
Subquery returned more than 1 value
這裏是我使用GETDATE()
的只是把人此刻的代碼和C.Values是我將一些XML分解到表中。
INSERT INTO [Container].[dsc].[DeviceConfiguration]
(DateInserted,
DeviceId,
ConfigurationId,
DateRegistered,
DateRemoved,
OperatingSystemInstallDate,
OperatingSystemSerialNumber
)
SELECT GETDATE(),
<This will need to be DeviceId>,
<This will need to be the ConfigurationId>,
GETDATE(),
GETDATE(),
C.value('@OSInstallDate', 'datetime'),
C.value('@OSSerialNumber', 'nvarchar(125)')
FROM [test].[HardwareComponent] CROSS APPLY
HardwareComponent.ComponentXmlData.nodes('OSData')AS T(C)
WHERE HardwareComponent.TypeId = 7
編輯: 更多信息對不起, 2列設置爲外鍵。
ALTER TABLE [dsc].[DeviceConfiguration]
WITH CHECK
ADD CONSTRAINT FK_DeviceConfiguration_Device
FOREIGN KEY (DeviceId)
REFERENCES [dsc].[Device](Id);
GO
ALTER TABLE [dsc].[DeviceConfiguration]
WITH CHECK
ADD CONSTRAINT FK_DeviceConfiguration_Configuration
FOREIGN KEY (ConfigurationId)
REFERENCES [dsc].[Configuration](Id);
GO
SELECT ID FROM DeviceId將檢索表DeviceId中的所有ID。 你錯過了一個WHERE。它真正取決於你的表結構(DeviceId和ConfigurationId)以及你應該如何從中獲取數據。 無論是那個還是DeviceId/ConfigurationId都是一個外鍵,並且您需要在這些表上插入您*插入的相同ID。 – 2010-09-01 09:24:00
事情是我有很多記錄進入表 – Matthew 2010-09-01 09:40:00