我有两张桌子。表A和表B. TableA包含varbinary(max)列 - 名为[BinaryA] TableB包含一个列(名为“Volume”,类型为“Long”),其中包含每个varbinary卷。
为了选择我查询的所有卷
SELECT ID, MyVolume = DATALENGTH([Binary])
FROM [VAULT].[TABLEA]
,我想用它的音量更新tableB。
然后我写了update [TableB]
set [VOLUME] = ( SELECT MyVolume = DATALENGTH([Binary])
FROM [VAULT].[TABLEA] ab
WHERE id = ab.[Id])
我收到的比
Cannot insert the value NULL into column 'Volume', table 'MySchema.Asset';
column does not allow nulls. UPDATE fails.
虽然我在运行
时没有收到任何NULLSELECT ID, MyVolume = DATALENGTH([Binary])
FROM [VAULT].[TABLEA]
答案 0 :(得分:4)
尝试使用此查询:
UPDATE TableB
SET TableB.[VOLUME] = DATALENGTH([T2.Binary])
FROM TableB
INNER JOIN [VAULT].[TABLEA] T2 ON TableB.TAL_ID = T2.TAL_ID
假设TableB和[VAULT]。[TABLEA]通过ID字段相关。
答案 1 :(得分:1)
UPDATE tableB
SET [volume] = (SELECT RetrieveAccountNumber.AccountNumber
FROM RetrieveAccountNumber
WHERE tableB.leadid =RetrieveAccountNumber.LeadID)
WHERE Sales_Import.leadid = (SELECT RetrieveAccountNumber.LeadID
FROM RetrieveAccountNumber
WHERE tableB.leadid = RetrieveAccountNumber.LeadID)