SQL select calculations - mysql

Below are the things I'm using
lahman's baseball -database
2015 SQL version of the database.
Microsoft SQL server management studio v17.7
I'm using "Los Angeles Dodgers" statistics and I'm basing my selects of
the website and pulling from the above database Website for ESPN Los Angeles Dodgers
I'm trying to recreate the website with 7 individual select statements. I'm having issues with my second select statements at the moment, The purpose of the second is to provide a totals row at the bottom like they do on the website.
( So my main question is can someone help with fixing my second select.)
( My second question can i get some assistance on creating 5 other
selects statements that correspond with the image below.)
(1st)
Main Body Select :
SELECT
nameFirst + ' ' + nameLast AS Name,
G AS GP,
AB,
R,
H,
H - B2 - B3 - HR AS S,
B2 AS '2B',
B3 AS '3B',
HR,
RBI,
(((H - B2 - B3 - HR) * 1.0) + (B2 * 2) + (B3 * 3) + (HR * 4)) AS 'TB',
BB,
SO,
SB,
(H * 1.0) / (CASE
WHEN AB = 0 THEN 1
ELSE AB
END) AS 'BA',
(CASE
WHEN (H + BB + HBP) = 0 THEN 0
ELSE ((H + BB + HBP) * 1.0)
END) / (CASE
WHEN (AB + BB + HBP) = 0 THEN 1.0
ELSE ((AB + BB + HBP) * 1.0)
END) AS 'OBP',
(CASE
WHEN (((H - B2 - B3 - HR) * 1.0) + (B2 * 2) + (B3 * 3) + (HR * 4)) = 0 THEN 0
ELSE (((H - B2 - B3 - HR) * 1.0) + (B2 * 2) + (B3 * 3) + (HR * 4))
END) / (CASE
WHEN AB = 0 THEN 1
ELSE AB
END) AS 'SLG',
(CASE
WHEN (H + BB + HBP) = 0 THEN 0
ELSE ((H + BB + HBP) * 1.0)
END) / (CASE
WHEN (AB + BB + HBP) = 0 THEN 1.0
ELSE ((AB + BB + HBP) * 1.0)
END) +
(CASE
WHEN (((H - B2 - B3 - HR) * 1.0) + (B2 * 2) + (B3 * 3) + (HR * 4)) = 0 THEN 0
ELSE (((H - B2 - B3 - HR) * 1.0) + (B2 * 2) + (B3 * 3) + (HR * 4))
END) / (CASE
WHEN AB = 0 THEN 1
ELSE AB
END) AS 'OPS'
FROM Players
LEFT OUTER JOIN Batting
ON Players.playerIDpk = Batting.playerID
WHERE teamID = 'LAN'
AND yearID = '2012'
ORDER BY BA DESC
Click Here - For Image of above select output
(2nd)
Total Select:
SELECT
'' AS Total,
'162' AS 'GP',
SUM(AB) AS 'AB',
SUM(R) AS 'R',
SUM(H) AS 'H',
SUM(B2) AS '2B',
SUM(B3) AS '3B',
SUM(HR) AS HR,
SUM(RBI) AS RBI,
SUM((((H - B2 - B3 - HR) * 1.0) + (B2 * 2) + (B3 * 3) + (HR * 4))) AS 'TB',
SUM(BB) AS BB,
SUM(SO) AS 'SO',
SUM(SB) AS 'SB',
AVG((H * 1.0) / (CASE
WHEN AB = 0 THEN 1
ELSE AB
END)) AS 'BA',
AVG((CASE
WHEN (H + BB + HBP) = 0 THEN 0
ELSE ((H + BB + HBP) * 1.0)
END) / (CASE
WHEN (AB + BB + HBP) = 0 THEN 1.0
ELSE ((AB + BB + HBP) * 1.0)
END)) AS 'OBP',
AVG((CASE
WHEN (((H - B2 - B3 - HR) * 1.0) + (B2 * 2) + (B3 * 3) + (HR * 4)) = 0 THEN 0
ELSE (((H - B2 - B3 - HR) * 1.0) + (B2 * 2) + (B3 * 3) + (HR * 4))
END) / (CASE
WHEN AB = 0 THEN 1
ELSE AB
END)) AS 'SLG',
AVG((CASE
WHEN (((H - B2 - B3 - HR) * 1.0) + (B2 * 2) + (B3 * 3) + (HR * 4)) = 0 THEN 0
ELSE (((H - B2 - B3 - HR) * 1.0) + (B2 * 2) + (B3 * 3) + (HR * 4))
END) / (CASE
WHEN AB = 0 THEN 1
ELSE AB
END)) AS 'OPS'
FROM Players
LEFT OUTER JOIN Batting
ON Players.playerIDpk = Batting.playerID
WHERE teamID = 'LAN'
AND yearID = '2012'
Here's what my total select returns and its incorrect.
Below is what it should return when i run the select for totals i don't know what i did wrong.

Looking at only the total value for the column BA it is clear that you are not doing the same calculations as them, instead of calculating average values you should calculate the ratio betweens the sum of the columns H and AB
So replace
AVG((H * 1.0) / (CASE
WHEN AB = 0 THEN 1
ELSE AB
END)) AS 'BA',
with
SUM(H) / SUM(AB) AS 'BA'
I haven't checked the other incorrect columns but I assume it's the same issue.

Related

SQLSERVER Running Balance

Actually i have problem on my query to get the running balance , i have debit and credit transaction i need one column to showing the cumulative running balance this is the code i used :
Select * From (
Select D.AccNo, H.[Date], A.AccountName, H.TrxNo,
(Case When ((D.Remark = '') or (D.Remark is Null)) Then H.Trxnote Else D.Remark End) As TrxDetailDescA,
(D.Debit * 1) AS DebitValue, (D.Credit * 1) AS CreditValue,SUM(COALESCE(D.Debit, 0) - COALESCE(D.Credit, 0)) AS Balance
From TblHeadTrans H, TblTransDetails D, TblAccount A
Where H.Guid = D.[LineNo]
And D.AccNo = A.AccountNo
And H.[Date] >= '01-01-2022' And H.[Date] <= '10-07-2022' And D.AccNo >= '1003'
group by AccNo,H.[Date],A.AccountName,H.TrxNo,D.Remark,h.Trxnote,d.Debit,d.Credit
Union All
Select D.AccNo, Null As TrxDate, A.AccountName, Null As TrxNo,
'Opening Balance' As TrxDetailDesc,
Case When (Sum(D.Debit * 1) - Sum(D.Credit *1)) < 0 then 0
Else (Sum(D.Debit * 1) - Sum(D.Credit * 1)) End As DebitValue,
Case When (Sum(D.Credit * 1) - Sum(D.Debit * 1)) < 0 then 0
Else (Sum(D.Credit * 1) - Sum(D.Debit * 1)) End As CreditValue
, SUM(COALESCE(d.Debit, 0) - COALESCE(d.credit, 0)) AS Balance
From TblHeadTrans H, TblTransDetails D, TblAccount A
Where H.guid = D.[LineNo] And D.AccNo = A.AccountNo
And d.[Date] < '01-01-2022' And D.accno = '1003'
Group By D.AccNo, A.AccountName,H.Date,H.TrxNo
) ReportData
WHERE 1=1
Order By AccNo, [Date], TrxNo
and the result showing as the picture:
the result

How to sort before using STUFF in SSRS

I have 2 different values I'm trying to STUFF here. It is Quantity + Price. For example: 1-$0.36; 100-$0.29; 25-$0.31. How can I have it sort by Quantity before being stuffed? (1,25,100 instead of 1,100,25) I did come across this link Sort data before concatenating using STUFF FOR XML, but it dealt with 1 value and I'm dealing with 2 values
SELECT STUFF(
(SELECT DISTINCT TOP (5)
'; ' + (CAST(FLOOR(CASE WHEN PCFBD.Quantity IS NOT NULL THEN PCFBD.Quantity ELSE 1 END) AS VARCHAR) + '-$' + CAST(REPLACE(REPLACE(RTRIM(REPLACE(
CASE WHEN PCF.PriceMethod = 0 THEN ROUND(I.CdCost / (100 - PCF.FormulaPercent) * 100, 2)
WHEN PCFBH.PriceFormula = 2 AND PCFBD.FormulaPercent IS NULL THEN ROUND(I.CdCost / (100 - PCF.FormulaPercent) * 100, 2)
WHEN PCFBH.PriceFormula = 2 AND PCFBD.FormulaPercent IS NOT NULL THEN ROUND(I.CdCost / (100 - PCFBD.FormulaPercent) * 100, 2)
WHEN PCFBH.PriceFormula = 1 THEN ROUND((I.ListPrice * (100 - PCFBD.FormulaPercent)) * .01,2)
ELSE NULL END, '000' ,'')), ' ','0') + '', '. ', '') AS VARCHAR))
FROM Item AS I
INNER JOIN PriceContractFamily AS PCF ON I.FamilyId = PCF.FamilyId
AND I.ItemStatus IN (0, 5)
INNER JOIN StockItem SI ON I.ItemId = SI.ItemId
AND SI.WarehouseId = '502E5876-C26B-4E11-8B88-AFE0C34ECF0D'
LEFT OUTER JOIN PriceContractFamilyBracketHeader AS PCFBH ON PCF.PriceContractFamilyId = PCFBH.PriceContractFamilyId
LEFT OUTER JOIN PriceContractFamilyBracketDetail AS PCFBD ON PCFBH.BracketHeaderId = PCFBD.BracketHeaderId
WHERE I.ListPrice = #ListPrice
AND LEFT(I.ItemNumber, 6) = #ItemNumber
AND PCF.PriceContractId = #PriceContractId
FOR XML PATH('')),1, 2, '') AS QtyPrice
You should be able to add an ORDER BY before the FOR XML PATH statement.

How to shorten this MySQL Query (colums use often the same sql parts...)

I am not an MySQL Professinal, but my query works fine
SELECT r.id,
/* Total repurchase price per Ton
* (Quantitiy/t * repurchase price/dry) + Extra Costs
*/
(
SUM((rc.menge / 1000) * (rw.preis / (IF (rw.is_zement = 1, 1.25 , 1)) / (1 - (IFNULL(rw.h2o, 0) / 100)))) +
SUM((rc.menge / 1000) * pr.preis) +
IF ((r.extra_1_type > 0), IF ((r.extra_1_type = 1), extra_1 , extra_1 * SUM(rc.menge / 1000)) , 0) +
IF ((r.extra_2_type > 0), IF ((r.extra_2_type = 1), extra_2 , extra_2 * SUM(rc.menge / 1000)) , 0) +
IF ((r.finanzierung_satz > 0) AND (r.finanzierung_monate > 0) AND SUM(rc.menge / 1000),
((r.finanzierung_satz / 100) / 12) * r.finanzierung_monate * (
SUM((rc.menge / 1000) * (rw.preis / (IF (rw.is_zement = 1, 1.25 , 1)) / (1 - (IFNULL(rw.h2o, 0) / 100)))) +
SUM((rc.menge / 1000) * pr.preis) +
IF ((r.extra_1_type > 0), IF ((r.extra_1_type = 1), extra_1 , extra_1 * SUM(rc.menge / 1000)) , 0) +
IF ((r.extra_2_type > 0), IF ((r.extra_2_type = 1), extra_2 , extra_2 * SUM(rc.menge / 1000)) , 0)
)
, 0) ) as repurchase_price,
/* Profit
* (Quantitiy/t * Price) - repurchase_price
*/
(SUM(rc.menge) / 1000 * r.vk) - (
SUM((rc.menge / 1000) * (rw.preis / (IF (rw.is_zement = 1, 1.25 , 1)) / (1 - (IFNULL(rw.h2o, 0) / 100)))) +
SUM((rc.menge / 1000) * pr.preis) +
IF ((r.extra_1_type > 0), IF ((r.extra_1_type = 1), extra_1 , extra_1 * SUM(rc.menge / 1000)) , 0) +
IF ((r.extra_2_type > 0), IF ((r.extra_2_type = 1), extra_2 , extra_2 * SUM(rc.menge / 1000)) , 0) +
IF ((r.finanzierung_satz > 0) AND (r.finanzierung_monate > 0) AND SUM(rc.menge / 1000),
((r.finanzierung_satz / 100) / 12) * r.finanzierung_monate * (
SUM((rc.menge / 1000) * (rw.preis / (IF (rw.is_zement = 1, 1.25 , 1)) / (1 - (IFNULL(rw.h2o, 0) / 100)))) +
SUM((rc.menge / 1000) * pr.preis) +
IF ((r.extra_1_type > 0), IF ((r.extra_1_type = 1), extra_1 , extra_1 * SUM(rc.menge / 1000)) , 0) +
IF ((r.extra_2_type > 0), IF ((r.extra_2_type = 1), extra_2 , extra_2 * SUM(rc.menge / 1000)) , 0)
)
, 0)
) as profit,
/* Profit Percentage
* Profit / (repurchase_price / 100)
*/
((SUM(rc.menge) / 1000 * r.vk) - (
SUM((rc.menge / 1000) * (rw.preis / (IF (rw.is_zement = 1, 1.25 , 1)) / (1 - (IFNULL(rw.h2o, 0) / 100)))) +
SUM((rc.menge / 1000) * pr.preis) +
IF ((r.extra_1_type > 0), IF ((r.extra_1_type = 1), extra_1 , extra_1 * SUM(rc.menge / 1000)) , 0) +
IF ((r.extra_2_type > 0), IF ((r.extra_2_type = 1), extra_2 , extra_2 * SUM(rc.menge / 1000)) , 0) +
IF ((r.finanzierung_satz > 0) AND (r.finanzierung_monate > 0) AND SUM(rc.menge / 1000),
((r.finanzierung_satz / 100) / 12) * r.finanzierung_monate * (
SUM((rc.menge / 1000) * (rw.preis / (IF (rw.is_zement = 1, 1.25 , 1)) / (1 - (IFNULL(rw.h2o, 0) / 100)))) +
SUM((rc.menge / 1000) * pr.preis) +
IF ((r.extra_1_type > 0), IF ((r.extra_1_type = 1), extra_1 , extra_1 * SUM(rc.menge / 1000)) , 0) +
IF ((r.extra_2_type > 0), IF ((r.extra_2_type = 1), extra_2 , extra_2 * SUM(rc.menge / 1000)) , 0)
)
, 0)
))
/
((
SUM((rc.menge / 1000) * (rw.preis / (IF (rw.is_zement = 1, 1.25 , 1)) / (1 - (IFNULL(rw.h2o, 0) / 100)))) +
SUM((rc.menge / 1000) * pr.preis) +
IF ((r.extra_1_type > 0), IF ((r.extra_1_type = 1), extra_1 , extra_1 * SUM(rc.menge / 1000)) , 0) +
IF ((r.extra_2_type > 0), IF ((r.extra_2_type = 1), extra_2 , extra_2 * SUM(rc.menge / 1000)) , 0) +
IF ((r.finanzierung_satz > 0) AND (r.finanzierung_monate > 0) AND SUM(rc.menge / 1000),
((r.finanzierung_satz / 100) / 12) * r.finanzierung_monate * (
SUM((rc.menge / 1000) * (rw.preis / (IF (rw.is_zement = 1, 1.25 , 1)) / (1 - (IFNULL(rw.h2o, 0) / 100)))) +
SUM((rc.menge / 1000) * pr.preis) +
IF ((r.extra_1_type > 0), IF ((r.extra_1_type = 1), extra_1 , extra_1 * SUM(rc.menge / 1000)) , 0) +
IF ((r.extra_2_type > 0), IF ((r.extra_2_type = 1), extra_2 , extra_2 * SUM(rc.menge / 1000)) , 0)
)
, 0)
) / 100)
as profit_percentage,
FROM recipe as r
LEFT JOIN recipecomponent as rc ON r.id = rc.recipe_id
LEFT JOIN rawmaterial as rw ON rc.rawmaterial_id = rw.id
LEFT JOIN press as pr ON r.press_id = pr.id
GROUP BY r.id
ORDER BY lieferdatum desc
As you can see, to calculate price, profit, profit percentage, I use often
the same parts... Is it possible to shorten my SQL Query? To make it more
'elegant' :)
Thank you & Best Regars Simon
As a generic answer, if you repeat caculations in your query, you can use derived tables to avoid repetition:
select d.a, d.b, d.a*d.b
from (
select x+y+z as a, d+e+f as b
from yourtable
) as d;

How to add the result of multiple aggregation functions in the same query?

I have a query that has a math calculations and aggregate functions as following:
SELECT u.username, u.id, COUNT(t.tahmin) AS tahmins_no,
SUM(t.result = 1) AS winnings,
SUM(t.result = 2) AS loses,
sum(case when t.tahmin = 1 and t.result = 1 then 1 else 0 end) * 1 as ms1,
sum(case when t.tahmin = 2 and t.result = 1 then 1 else 0 end) * 3 as ms0,
sum(case when t.tahmin = 3 and t.result = 1 then 1 else 0 end) * 1 as ms2,
sum(case when t.tahmin = 4 and t.result = 1 then 1 else 0 end) * 2 as alt,
sum(case when t.tahmin = 5 and t.result = 1 then 1 else 0 end) * 2 as ust,
sum(case when t.tahmin = 6 and t.result = 1 then 1 else 0 end) * 3 as tg_0_1,
sum(case when t.tahmin = 7 and t.result = 1 then 1 else 0 end) * 2 as tg_2_3,
sum(case when t.tahmin = 8 and t.result = 1 then 1 else 0 end) * 4 as tg_4_6,
sum(case when t.tahmin = 9 and t.result = 1 then 1 else 0 end) * 20 as tg_7,
sum(case when t.tahmin = 10 and t.result = 1 then 1 else 0 end) * 1 as kg_var,
sum(case when t.tahmin = 11 and t.result = 1 then 1 else 0 end) * 1 as kg_yok
sum(ms1 + ms0 + ms2 + alt + ust + tg_0_1 + tg_2_3 + tg_4_6 + tg_7 + kg_var + kg_yok) as total
FROM users u
LEFT JOIN tahminler t ON u.id = t.user_id
LEFT JOIN matches_of_comments mc ON t.match_id = mc.match_id
WHERE MONTH(STR_TO_DATE(mc.match_date, '%d.%m.%Y')) = 01 AND
YEAR(STR_TO_DATE(mc.match_date, '%d.%m.%Y')) = 2014 AND flag=1
GROUP BY u.id
HAVING tahmins_no > 0
ORDER BY total DESC
The query is working very well and I get the expected results the only problem is when I add the following line to the query :
sum(ms1 + ms0 + ms2 + alt + ust + tg_0_1 + tg_2_3 + tg_4_6 + tg_7 + kg_var + kg_yok) as total
I want to order my columns by total I want to know is that line is correct or not? is the syntax of it correct or not?
You're trying to get a SUM of SUMs (noz needed in that case) and you want to reuse an alias, both are not allowed in Standard SQL (without Derived Tables).
If it's only for sorting you simply need to
ORDER BY ms1 + ms0 + ms2 + alt + ust + tg_0_1 + tg_2_3 + tg_4_6 + tg_7 + kg_var + kg_yok DESC
If you want to display the TOTAL in your SELECT list you need to repeat the calculation:
sum(case when t.tahmin = 1 and t.result = 1 then 1 else 0 end) * 1 +
sum(case when t.tahmin = 2 and t.result = 1 then 1 else 0 end) * 3 +
....
sum(case when t.tahmin = 11 and t.result = 1 then 1 else 0 end) * 1 as TOTAL
or better use a Derived Table:
SELECT username, id, tahmins_no,
winnings,
loses,
ms1,
ms0,
...
kg_yok,
ms1 + ms0 + ms2 + alt + ust + tg_0_1 + tg_2_3 + tg_4_6 + tg_7 + kg_var + kg_yok as TOTAL
FROM
(
your existing query (without ORDER BY)
) as dt
ORDER BY TOTAL DESC
Your special sum is not actually a sum but a simple addition, which should be made using a wrapper query.
The sums of your query can be simplified by using the fact that in mysql true is 1 and false is 0 (as you are already doing for winnings and loses).
You also have a defect in your group by clause: You must list all non-aggregate columns (ie username and id) otherwise you will get non-standard behaviour (ie the wrong result). Note how this too can also be expressed more simply.
Try this:
SELECT *, ms1 + ms0 + ms2 + alt + ust + tg_0_1 + tg_2_3 + tg_4_6 + tg_7 + kg_var + kg_yok as total FROM (
SELECT
u.username,
u.id,
COUNT(t.tahmin) AS tahmins_no,
SUM(t.result = 1) AS winnings,
SUM(t.result = 2) AS loses,
sum(t.tahmin = 1 and t.result = 1) * 1 as ms1,
sum(t.tahmin = 2 and t.result = 1 then 1 else 0 end) * 3 as ms0,
sum(t.tahmin = 3 and t.result = 1) * 1 as ms2,
sum(t.tahmin = 4 and t.result = 1) * 2 as alt,
sum(t.tahmin = 5 and t.result = 1) * 2 as ust,
sum(t.tahmin = 6 and t.result = 1) * 3 as tg_0_1,
sum(t.tahmin = 7 and t.result = 1) * 2 as tg_2_3,
sum(t.tahmin = 8 and t.result = 1) * 4 as tg_4_6,
sum(t.tahmin = 9 and t.result = 1) * 20 as tg_7,
sum(t.tahmin = 10 and t.result = 1) * 1 as kg_var,
sum(t.tahmin = 11 and t.result = 1) * 1 as kg_yok
FROM users u
LEFT JOIN tahminler t ON u.id = t.user_id
LEFT JOIN matches_of_comments mc ON t.match_id = mc.match_id
WHERE MONTH(STR_TO_DATE(mc.match_date, '%d.%m.%Y')) = 01
AND YEAR(STR_TO_DATE(mc.match_date, '%d.%m.%Y')) = 2014
AND flag=1
GROUP BY 1, 2
HAVING tahmins_no > 0) x
ORDER BY total DESC

How do I prevent NaN from appearing in my reports?

The following code returns a NaN in situations where there are no records. How do I prevent this from being displayed in the report? A 0 would be preferred.
=FormatNumber(
((
(Code.NullSafeSplit(Fields!AvgLOSC1.Value, 0) * Code.NullSafeSplit(Fields!AvgLOSC1.Value, 1)) +
(Code.NullSafeSplit(Fields!AvgLOSC2.Value, 0) * Code.NullSafeSplit(Fields!AvgLOSC2.Value, 1)) +
(Code.NullSafeSplit(Fields!AvgLOSC3.Value, 0) * Code.NullSafeSplit(Fields!AvgLOSC3.Value, 1)) +
(Code.NullSafeSplit(Fields!AvgLOSC4.Value, 0) * Code.NullSafeSplit(Fields!AvgLOSC4.Value, 1)) +
(Code.NullSafeSplit(Fields!AvgLOSC5.Value, 0) * Code.NullSafeSplit(Fields!AvgLOSC5.Value, 1))
) / (
CInt(Code.NullSafeSplit(Fields!AvgLOSC1.Value, 1)) +
CInt(Code.NullSafeSplit(Fields!AvgLOSC2.Value, 1)) +
CInt(Code.NullSafeSplit(Fields!AvgLOSC3.Value, 1)) +
CInt(Code.NullSafeSplit(Fields!AvgLOSC4.Value, 1)) +
CInt(Code.NullSafeSplit(Fields!AvgLOSC5.Value, 1))
))
, 0)
I think the formula below should get it. I haven't tested this, so I might be missing a parenthesis. The problem is likely coming from a divide by zero when all entries are null. This catches that and sets the divisor to 1 in that case.
=FormatNumber(
(
(Code.NullSafeSplit(Fields!AvgLOSC1.Value, 0) * Code.NullSafeSplit(Fields!AvgLOSC1.Value, 1)) +
(Code.NullSafeSplit(Fields!AvgLOSC2.Value, 0) * Code.NullSafeSplit(Fields!AvgLOSC2.Value, 1)) +
(Code.NullSafeSplit(Fields!AvgLOSC3.Value, 0) * Code.NullSafeSplit(Fields!AvgLOSC3.Value, 1)) +
(Code.NullSafeSplit(Fields!AvgLOSC4.Value, 0) * Code.NullSafeSplit(Fields!AvgLOSC4.Value, 1)) +
(Code.NullSafeSplit(Fields!AvgLOSC5.Value, 0) * Code.NullSafeSplit(Fields!AvgLOSC5.Value, 1))
)
/
(
IIF((
CInt(Code.NullSafeSplit(Fields!AvgLOSC1.Value, 1)) +
CInt(Code.NullSafeSplit(Fields!AvgLOSC2.Value, 1)) +
CInt(Code.NullSafeSplit(Fields!AvgLOSC3.Value, 1)) +
CInt(Code.NullSafeSplit(Fields!AvgLOSC4.Value, 1)) +
CInt(Code.NullSafeSplit(Fields!AvgLOSC5.Value, 1))
) = 0,
1,
(
CInt(Code.NullSafeSplit(Fields!AvgLOSC1.Value, 1)) +
CInt(Code.NullSafeSplit(Fields!AvgLOSC2.Value, 1)) +
CInt(Code.NullSafeSplit(Fields!AvgLOSC3.Value, 1)) +
CInt(Code.NullSafeSplit(Fields!AvgLOSC4.Value, 1)) +
CInt(Code.NullSafeSplit(Fields!AvgLOSC5.Value, 1))
)
)
, 0)