我有一个程序尝试在每个代理的表中插入样本,每个代理的样本数根据某些计算而变化
Declare @samplesize int
Declare @Top int
set @samplesize=0
;WITH DataToInsert AS
(
Select AgentID, Surveys, LOB,(case when day(getdate())<4 then 3 else (day(getdate())) - (Surveys*3) end) SampleSize from Current_Agent_SurveyCount_HSI Where surveys<8
)
--Insert Into Survey_Source_New (LOB, CenterName, CallDate, AgentZid, TN, Ticket, RecordingID, Cycle, [TimeStamp])
--Select top 5 ss.LOB, CenterName, CallDate, AgentZid, TN, Ticket, RecordingID, Cycle, [TimeStamp]
--From Survey_source_Level1 ss
--inner join DataToInsert du on ss.AgentZID=du.agentID
--where flag is null and du.samplesize>6
--order by newid()
Insert Into Survey_Source_New (LOB, CenterName, CallDate, AgentZid, TN, Ticket, RecordingID, Cycle, [TimeStamp])
Select top (@Top) @Top=du.samplesize,ss.LOB, CenterName, CallDate, AgentZid, TN, Ticket, RecordingID, Cycle, [TimeStamp]
From Survey_source_Level1 ss
inner join DataToInsert du on ss.AgentZID=du.agentID
where flag is null and du.samplesize<7
order by newid()
我在这里得到的错误是
消息 4115,级别 15,状态 1,第 4 行
TOP 子句的参数中不允许引用列“samplesize”。此处仅允许引用外部范围内的列或独立表达式和子查询。
有解决方法吗?
任何帮助表示赞赏。
提前致谢。