我有一个3列的格式,但我有一个客户需求,格式如下。我把所有的东西都整理好了,但总量很大。
pcn charge 100
court fee 15
solictors costs 00
total amount 115
Requirment
PCN charge - 7 (100) = 0010000
court fee - 5 (15) = 01500
solictors cost - 5 (0) = 00000
total amount - 8 (115)= 00011500 ( I am not getting this value i get 00000115.)
这是我的疑问:
"RIGHT('00'+CAST(CAST(bat.PCN_Charge* 100.00 AS INT) AS VARCHAR(5)),7) as CLAIMAMT," +
"RIGHT('0'+CAST(CAST([CFee] * 100 AS INT) AS VARCHAR(5)),5) as CFEE," +
"RIGHT('00000'+CAST(CAST([Solictors Fees] AS INT) AS VARCHAR(5)),5)," +
"RIGHT('00000'+CAST(CAST(bat.PCN_Charge + [CFee] AS INT) AS VARCHAR(5)),8) as TotalAMT " +
答案 0 :(得分:2)
我认为在SQL Server中保留填充数字的最简单方法是添加一个大整数并选取最右边的列。这就是我的意思:
select right(100000000 + CAST(bat.PCN_Charge * 100.00 AS INT), 7),
right(100000000 + CAST([CFee] * 100 AS INT), 5),
right(100000000 + CAST([Solictors Fees] AS INT), 5),
right(100000000 + CAST(bat.PCN_Charge*100 + [CFee]*100 AS INT), 8)
请注意,我将*100
添加到总数中。我认为这也是您的代码中缺少的内容。