【发布时间】:2018-01-25 03:39:41
【问题描述】:
我确信其他人不得不做类似的事情,但我很难找到我需要的示例。
我有一个可能随时间变化的数组。我正在尝试使用该数组在我的团队之间平均分配我的帐户组合。我无法直接更改 SQL 数据库,因此我必须通过 XML 提取并重新上传来完成此操作。
这是伪代码(请原谅我写了奇怪的伪代码):
Declare @Collector as array
Declare @LoopedValue as varchar (60)
set @Collector [Team1, Team2, Team3]
Set @LoopedValue to index 0 of array
For each row returned
SELECT
'<LOAN UpdateFlag= "1" LoanNumber= "'+la.loan_number+'" CollectionOfficerNumber= "'+@LoopedValue+'"> </LOAN>'
FROM loanacct la
where
la.portfolio_code_id = 1
AND status_code_no = 0
AND la.acctrefno not IN (SELECT las.acctrefno from loanacct_statuses AS las where las.status_code_no IN (11, 12, 13, 14, 17, 19, 20, 22, 26, 28, 35, 36, 38, 39, 62)
)
--Excludes accounts with Status Codes 11=Repossessed; 12=Pending Repo; 13=Bankruptcy Ch 7; 14=Charge-off; 17=Unsecured bad debt; 19=Clear to sell; 20=Bankruptcy Ch. 13; 22=Repo Sold; 26:Voluntary repossession; 28=Move to inventory; 35=Deficiency; 36=Unsecured Balance; 38=Discharged Ch 7 BK; 39=Discharged Ch13 BK: 62=Pre-Bankruptcy
Set @LoopedValue to @LoopedValue+1.
If @LoopedValue > 2 set @LoopedValue to 0 Else end
end
ORDER by la.days_past_due desc
我的问题是,我到底要在@LoopedValue 部分中添加什么来实现 Column 1 = Team1、Column 2 = Team2、Column3 = Team3、Column4 = Team1 等结果?
我实际上不想在团队之间分配随机值,因为这可能会造成帐户难度的不平衡。
【问题讨论】:
-
您好,欢迎来到 SO。我可以向您保证,您不想为此使用循环。但是,您在这里要做什么还不清楚。这是一个很好的起点。 spaghettidba.com/2015/04/24/…
-
我认为您可以在选择中使用 row_number() 并通过使用行号的模数按团队数得出索引。这将为三个团队生成索引 0、1、2、0、1、2 等的循环。
标签: sql-server