我有以下插页:
INSERT INTO TransactionActivityLog
(
[UserName]
,[ApplicationId]
,[ActivityType]
,[ActivityDate]
,[ActivityAllowed]
,[ResultCode]
,[ResultMessage]
,[CCTransactionId]
,[CCMasterTokenId]
,[PaymentTransactionStatus]
,[CCMasterTokenStatus]
,[AdditionalData]
,[TargetUserId]
,[BranchId]
)
VALUES
(
'UserName' + CONVERT(varchar(5), @TargetRowCount) -- UserName
,'00000000-0000-0000-0000-000000000000' -- ApplicationId
,FLOOR(RAND()*(4-0)+0) -- ActivityType
,DATEADD(DAY, RAND(CHECKSUM(NEWID()))*(1+DATEDIFF(DAY, @FromDate, @ToDate)), @FromDate) -- ActivityDate
,1 -- ActivityAllowed
,NULL -- ResultCode
,NULL -- ResultMessage
,SELECT TOP 1 Id FROM CCTransactions ORDER BY NEWID() -- CCTransactionId (Needs referencing to CCTransactions table!)
,NULL -- CCMasterTokenId (Needs referencing to CCMasterToken table!)
,-1 -- PaymentTransactionStatus
,FLOOR(RAND()*(6-0)+0) -- CCMasterTokenStatus
,'AdditionalData' + CONVERT(varchar(5), @TargetRowCount) -- AdditionalData
,'00000000-0000-0000-0000-000000000000' -- TargetUserId
,ABS(Checksum(NewID()) % 5) + 1 -- BranchId
)
该行:
SELECT TOP 1 Id FROM CCTransactions ORDER BY NEWID()
在SSMS中产生错误(SQL Server 2012)。
我的意图是;我想从表 CCTransactions 中随机选择一行,然后选择其ID并在上面的INSERT语句中插入其值。
我做错了什么?
答案 0 :(得分:0)
使用如下
null,
(SELECT TOP 1 Id FROM CCTransactions ORDER BY NEWID())
null
...