I am trying to create a view and the select statement is exactly what I want to see, but when I use that exact same select statement as the create view statement its parses the information differently. Here is the select statement.
CREATE VIEW shippingview
AS
( SELECT shipcarton.id AS shipcartonid
,ship.num AS shipnum
,so.num AS sonum
,so.customerpo AS customerpo
,so.email AS email
,so.phone AS phone
,countryconst.abbreviation AS country
,stateconst.code AS STATE
,ship.shiptozip AS postalcode
,ship.shiptocity AS city
,carrierservice.name AS servicename
,carrierservice.code AS servicecode
,shipcarton.freightweight AS weight
,shipcarton.len AS length
,shipcarton.height AS height
,shipcarton.width AS width
,`ship`.`id` AS `shipID`
,(
CASE
WHEN (locate('\n', `ship`.`shipToAddress`) > 0)
THEN substr(`ship`.`shipToAddress`, 1, (locate('\n', `ship`.`shipToAddress`) - 1))
ELSE `ship`.`shipToAddress`
END
) AS `SHIPTOADDRESS1`
,(
CASE
WHEN (
(locate('\n', `ship`.`shipToAddress`) > 0)
AND (locate('\n', `ship`.`shipToAddress`, (locate('\n', `ship`.`shipToAddress`) + 1)) = 0)
)
THEN substr(`ship`.`shipToAddress`, (locate('\n', `ship`.`shipToAddress`) + 1))
WHEN (
(locate('\n', `ship`.`shipToAddress`) > 0)
AND (locate('\n', `ship`.`shipToAddress`, (locate('\n', `ship`.`shipToAddress`) + 1)) > 0)
)
THEN substr(`ship`.`shipToAddress`, (locate('\n', `ship`.`shipToAddress`) + 1), (locate('\n', `ship`.`shipToAddress`, (locate('\n', `ship`.`shipToAddress`) + 1)) - (locate('\n', `ship`.`shipToAddress`) + 1)))
ELSE ''
END
) AS `SHIPTOADDRESS2`
,(
CASE
WHEN (locate('\n', `ship`.`shipToAddress`, (locate('\n', `ship`.`shipToAddress`) + 1)) > 0)
THEN substr(`ship`.`shipToAddress`, (locate('\n', `ship`.`shipToAddress`, (locate('\n', `ship`.`shipToAddress`) + 1)) + 1))
ELSE ''
END
) AS `SHIPTOADDRESS3`
FROM ship
LEFT JOIN so ON ship.soid = so.id
LEFT JOIN carrierservice ON ship.carrierserviceid = carrierservice.id
LEFT JOIN countryconst ON ship.shiptocountryid = countryconst.id
LEFT JOIN stateconst ON ship.shiptostateid = stateconst.id
LEFT JOIN shipcarton ON shipcarton.shipid = ship.id
WHERE ship.statusid IN (
10
,20
)
)
It supposed to display address seperated by line breaks and it works completely correctly as the select and not the create.
Related
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
The SQL statement below produce sums of data for months and displays the columns as years.
The problem, as you will see in the image below, is that the result set has null values. Is there a way to represent the dataset for each month once?
SELECT
DATE_FORMAT(start_date, '%M') AS M,
(CASE DATE_FORMAT(start_date, '%Y')
WHEN
2015
THEN
ROUND((COALESCE(SUM(b.bid_amount), 0) + COALESCE(SUM(b.hourly_bid_amount), 0) + COALESCE(SUM(b.other_bid_amount), 0) * pcntg.percentage / 100 + SUM(b.other_bid_amount) - COALESCE(SUM(b.subcontracted_amount), 0)),
2) + COALESCE(SUM(b.subcontracted_amount), 0) + COALESCE(SUM(b.contingency_1), 0)
END) AS '2015',
(CASE DATE_FORMAT(start_date, '%Y')
WHEN
2016
THEN
ROUND((COALESCE(SUM(b.bid_amount), 0) + COALESCE(SUM(b.hourly_bid_amount), 0) + COALESCE(SUM(b.other_bid_amount), 0) * pcntg.percentage / 100 + SUM(b.other_bid_amount) - COALESCE(SUM(b.subcontracted_amount), 0)),
2) + COALESCE(SUM(b.subcontracted_amount), 0) + COALESCE(SUM(b.contingency_1), 0)
END) AS '2016',
(CASE DATE_FORMAT(start_date, '%Y')
WHEN
2017
THEN
ROUND((COALESCE(SUM(b.bid_amount), 0) + COALESCE(SUM(b.hourly_bid_amount), 0) + COALESCE(SUM(b.other_bid_amount), 0) * pcntg.percentage / 100 + SUM(b.other_bid_amount) - COALESCE(SUM(b.subcontracted_amount), 0)),
2) + COALESCE(SUM(b.subcontracted_amount), 0) + COALESCE(SUM(b.contingency_1), 0)
END) AS '2017',
(CASE DATE_FORMAT(start_date, '%Y')
WHEN
2018
THEN
ROUND((COALESCE(SUM(b.bid_amount), 0) + COALESCE(SUM(b.hourly_bid_amount), 0) + COALESCE(SUM(b.other_bid_amount), 0) * pcntg.percentage / 100 + SUM(b.other_bid_amount) - COALESCE(SUM(b.subcontracted_amount), 0)),
2) + COALESCE(SUM(b.subcontracted_amount), 0) + COALESCE(SUM(b.contingency_1), 0)
END) AS '2018'
FROM
phases_required b
RIGHT JOIN
projects a ON b.project_id = a.id
LEFT JOIN
(SELECT
t2.project_id, ROUND(reimbursable_percent, 0) AS percentage
FROM
rate_names t1, phases_required t2, rates_phase t3
WHERE
t1.id = t3.rate_names_id
AND t3.rates_id = t2.rates_id
GROUP BY t2.project_id) AS pcntg ON pcntg.project_id = a.id
WHERE
start_date != '0000-00-00'
AND DATE_FORMAT(start_date, '%Y') NOT IN (2010 , 2012, 2013, 2014)
GROUP by DATE_FORMAT(start_date, '%m%Y')
Here is the SQL to produce the table SQL statement you see above dynamically:
SET SESSION group_concat_max_len = 10000000000;
SET #sqldynamic = (
SELECT
GROUP_CONCAT( distinct
CONCAT( '(case date_format(start_date,"%Y") when ', date_format(a.start_date,"%Y") , ' then ROUND((COALESCE(sum(b.bid_amount), 0) + COALESCE(sum(b.hourly_bid_amount),0) + COALESCE(sum(b.other_bid_amount), 0) * pcntg.percentage/100 + sum(b.other_bid_amount) - COALESCE(sum(b.subcontracted_amount),0)),2)+COALESCE(sum(b.subcontracted_amount),0)+COALESCE(sum(b.contingency_1),0) end) as \'' , date_format(start_date,"%Y"),'\''
)
)
From phases_required b RIGHT JOIN projects a ON b.project_id = a.id LEFT JOIN (SELECT t2.project_id, round(reimbursable_percent,0) as percentage FROM rate_names t1,phases_required t2,rates_phase t3
WHERE t1.id = t3.rate_names_id AND t3.rates_id = t2.rates_id group by t2.project_id) as pcntg on pcntg.project_id =a.id
WHERE start_date != "0000-00-00" and date_format(start_date,"%Y") not in (2010,2012,2013,2014)
);
SET #sql = CONCAT('SELECT date_format(start_date,"%M") as M, ',
#sqldynamic, '
From phases_required b RIGHT JOIN projects a ON b.project_id = a.id LEFT JOIN (SELECT t2.project_id, round(reimbursable_percent,0) as percentage FROM rate_names t1,phases_required t2,rates_phase t3
WHERE t1.id = t3.rate_names_id AND t3.rates_id = t2.rates_id group by t2.project_id) as pcntg on pcntg.project_id =a.id
WHERE start_date != "0000-00-00" and date_format(start_date,"%Y") not in (2010,2012,2013,2014)
group by date_format(start_date,"%M%Y") order by date_format(start_date,"%m")'
);
PREPARE stmt FROM #sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
I don't like but it should works :
select m,
sum(coalesce('2015', 0)) '2015',
sum(coalesce('2015', 0)) '2016',
sum(coalesce('2015', 0)) '2017',
sum(coalesce('2015', 0)) '2018'
from (
SELECT
DATE_FORMAT(start_date, '%M') AS M,
(CASE DATE_FORMAT(start_date, '%Y')
WHEN
2015
THEN
ROUND((COALESCE(SUM(b.bid_amount), 0) + COALESCE(SUM(b.hourly_bid_amount), 0) + COALESCE(SUM(b.other_bid_amount), 0) * pcntg.percentage / 100 + SUM(b.other_bid_amount) - COALESCE(SUM(b.subcontracted_amount), 0)),
2) + COALESCE(SUM(b.subcontracted_amount), 0) + COALESCE(SUM(b.contingency_1), 0)
END) AS '2015',
(CASE DATE_FORMAT(start_date, '%Y')
WHEN
2016
THEN
ROUND((COALESCE(SUM(b.bid_amount), 0) + COALESCE(SUM(b.hourly_bid_amount), 0) + COALESCE(SUM(b.other_bid_amount), 0) * pcntg.percentage / 100 + SUM(b.other_bid_amount) - COALESCE(SUM(b.subcontracted_amount), 0)),
2) + COALESCE(SUM(b.subcontracted_amount), 0) + COALESCE(SUM(b.contingency_1), 0)
END) AS '2016',
(CASE DATE_FORMAT(start_date, '%Y')
WHEN
2017
THEN
ROUND((COALESCE(SUM(b.bid_amount), 0) + COALESCE(SUM(b.hourly_bid_amount), 0) + COALESCE(SUM(b.other_bid_amount), 0) * pcntg.percentage / 100 + SUM(b.other_bid_amount) - COALESCE(SUM(b.subcontracted_amount), 0)),
2) + COALESCE(SUM(b.subcontracted_amount), 0) + COALESCE(SUM(b.contingency_1), 0)
END) AS '2017',
(CASE DATE_FORMAT(start_date, '%Y')
WHEN
2018
THEN
ROUND((COALESCE(SUM(b.bid_amount), 0) + COALESCE(SUM(b.hourly_bid_amount), 0) + COALESCE(SUM(b.other_bid_amount), 0) * pcntg.percentage / 100 + SUM(b.other_bid_amount) - COALESCE(SUM(b.subcontracted_amount), 0)),
2) + COALESCE(SUM(b.subcontracted_amount), 0) + COALESCE(SUM(b.contingency_1), 0)
END) AS '2018'
FROM
phases_required b
RIGHT JOIN
projects a ON b.project_id = a.id
LEFT JOIN
(SELECT
t2.project_id, ROUND(reimbursable_percent, 0) AS percentage
FROM
rate_names t1, phases_required t2, rates_phase t3
WHERE
t1.id = t3.rate_names_id
AND t3.rates_id = t2.rates_id
GROUP BY t2.project_id) AS pcntg ON pcntg.project_id = a.id
WHERE
start_date != '0000-00-00'
AND DATE_FORMAT(start_date, '%Y') NOT IN (2010 , 2012, 2013, 2014)
GROUP by DATE_FORMAT(start_date, '%m%Y')
) qry
group by m;
Here is the answer. Thank you Daniel Blais for helping getting me here.
SET SESSION group_concat_max_len = 10000000000;
SET #sqldynamic = (
SELECT
GROUP_CONCAT( distinct
CONCAT( '(case date_format(start_date,"%Y") when ', date_format(a.start_date,"%Y") , ' then ROUND((COALESCE(sum(b.bid_amount), 0) + COALESCE(sum(b.hourly_bid_amount),0) + COALESCE(sum(b.other_bid_amount), 0) * pcntg.percentage/100 + sum(b.other_bid_amount) - COALESCE(sum(b.subcontracted_amount),0)),2)+COALESCE(sum(b.subcontracted_amount),0)+COALESCE(sum(b.contingency_1),0) end) as Y_' , date_format(start_date,"%Y")
)
)
From phases_required b RIGHT JOIN projects a ON b.project_id = a.id LEFT JOIN (SELECT t2.project_id, round(reimbursable_percent,0) as percentage FROM rate_names t1,phases_required t2,rates_phase t3
WHERE t1.id = t3.rate_names_id AND t3.rates_id = t2.rates_id group by t2.project_id) as pcntg on pcntg.project_id =a.id
WHERE start_date != "0000-00-00" and date_format(start_date,"%Y") not in (2010,2012,2013,2014)
);
SET #sqlgroup = (
SELECT
GROUP_CONCAT(distinct
CONCAT('sum(coalesce(Y_', date_format(a.start_date,"%Y") ,', 0)) as Y_',date_format(a.start_date,"%Y")
)
)
From phases_required b RIGHT JOIN projects a ON b.project_id = a.id LEFT JOIN (SELECT t2.project_id, round(reimbursable_percent,0) as percentage FROM rate_names t1,phases_required t2,rates_phase t3
WHERE t1.id = t3.rate_names_id AND t3.rates_id = t2.rates_id group by t2.project_id) as pcntg on pcntg.project_id =a.id
WHERE start_date != "0000-00-00" and date_format(start_date,"%Y") not in (2010,2012,2013,2014)
);
SET #sql = CONCAT('select m,', #sqlgroup , ' from (SELECT date_format(start_date,"%M") as M, date_format(start_date,"%m") as m2 ,',
#sqldynamic, '
From phases_required b RIGHT JOIN projects a ON b.project_id = a.id LEFT JOIN (SELECT t2.project_id, round(reimbursable_percent,0) as percentage FROM rate_names t1,phases_required t2,rates_phase t3
WHERE t1.id = t3.rate_names_id AND t3.rates_id = t2.rates_id group by t2.project_id) as pcntg on pcntg.project_id =a.id
WHERE start_date != "0000-00-00" and date_format(start_date,"%Y") not in (2010,2012,2013,2014)
group by date_format(start_date,"%M%Y") order by date_format(start_date,"%m")) qry group by m order by m2'
);
PREPARE stmt FROM #sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
Here is an example:
[U_TipTon]=118.7->59.35;[U_Haulge]=428.28->214.14
I need to extract just 118.7->59.35 as Tipton, and 428.28->214.14 in another column as U_Haulage.
The length of the string is variable as well as the posision os my pattern word.
I am trying with Patindex but I cannot find the way.
In MySQL there's SUBSTRING_INDEX, which extracts a substring based on a delimiter:
select
substring_index(substring_index(x, '[U_TipTon]=', -1), ';', 1) as TipTon
,substring_index(substring_index(x, '[U_Haulge]=', -1), ';', 1) as Haulge
from
(
select '[U_TipTon]=118.7->59.35;[U_Haulge]=428.28->214.14' as x
) as dt
Edit:
In MS SQL Server it's more complicated:
select
substring(xHaulge, 1, charindex(';', xHaulge + ';')-1) as Haulge,
substring(xTipTon, 1, charindex(';', xTipTon + ';')-1) as TipTon
from
(
select
case when charindex('[U_Haulge]=', x) > 0
then substring(x, charindex('[U_Haulge]=', x) + len('[U_Haulge]='), 8000)
else ''
end as xHaulge,
case when charindex('[U_TipTon]=', x) > 0
then substring(x, charindex('[U_TipTon]=', x) + len('[U_TipTon]='), 8000)
else ''
end as xTipTon
from
(
select '[U_TipTon]=118.7->59.35;[U_Haulge]=428.28->214.14' as x
) as dt
) as dt
The solution was:
case
when charindex('Haulge',t.xField) > 0 then
substring( t.xField , charindex('Haulge',t.xField) + 8,case when charindex(';',substring( t.xField , charindex('Haulge',t.xField) + 8,LEN(t.xField))) = 0
then LEN(t.xField)
else charindex(';',substring( t.xField , charindex('Haulge',t.xField) + 8,LEN(t.xField)))-1 end )
else '-' end [Haul Price]
,case
when charindex('Tipton',t.xField) > 0 then
substring( t.xField , charindex('TipTon',t.xField) + 8,case when charindex(';',substring( t.xField , charindex('Tipton',t.xField) + 8,LEN(t.xField))) = 0
then LEN(t.xField)
else charindex(';',substring( t.xField , charindex('Tipton',t.xField) + 8,LEN(t.xField)))-1 end )
else '-' end [Tip Price]
,case
when charindex('AItmPr',t.xField) > 0 then
substring( t.xField , charindex('AItmPr',t.xField) + 8,case when charindex(';',substring( t.xField , charindex('AItmPr',t.xField) + 8,LEN(t.xField))) = 0
then LEN(t.xField)
else charindex(';',substring( t.xField , charindex('AItmPr',t.xField) + 8,LEN(t.xField)))-1 end )
else '-' end [Additional Price]
Good evening to all,
as the subject, I have a query in which parameters can be used, preceded by the # character, in order to do the calculations. In order to test this query using MySQL Front. The problem is that if you launch the query the first time, I expected returns data, but if you run it again, I do not return anything. I also tried using Toad, but from the first attempt did not return anything. Thank you in advance.
SELECT(
SUM(
PzProd1 +
PzProd2 +
PzProd3 +
PzProd4 +
PzProd5 +
PzProd6
)) AS Pezzi_Prodotti,
PSLC.PSLC_Prod.LineaID as linea,
PSLC.PSLC_Prod.SezioneID,
PSLC.PSLC_Prod.Desc_Prod,
#cod_spezz := PSLC.PSLC_Prod.cod_spezz_1,
#l_spezz := REPLACE(FORMAT((SUBSTRING_INDEX(
PSLC.PSLC_Prod.lung_Spezz_1, '± ', 1) / 1000) ,2) , ',' , '.'
) as lunghezza_Spezzone,
REPLACE(FORMAT( #MtScrap := SUM(MtScrap) , 0) , ',' , '.') as MtScarto,
REPLACE(FORMAT((#MtScrap / #l_spezz),0), ',' , '.') as ScartoInPezzi ,
REPLACE(FORMAT(SUM((PzProd1 + PzProd2 + PzProd3 + PzProd4 + PzProd5 + PzProd6) * #l_spezz) ,0), ',' , '.') as MT_Prodotti,
REPLACE(FORMAT( #xxx := (
SUM(IF(PSLC.PSLC_CAUSALI.AvailableCausa_1 NOT LIKE ('%sezione%'),PSLC.PSLC_CAUSALI.AvailableTotTime_1 , 0)) +
SUM(IF(PSLC.PSLC_CAUSALI.AvailableCausa_2 NOT LIKE ('%sezione%'),PSLC.PSLC_CAUSALI.AvailableTotTime_2 , 0)) +
SUM(IF(PSLC.PSLC_CAUSALI.AvailableCausa_3 NOT LIKE ('%sezione%'),PSLC.PSLC_CAUSALI.AvailableTotTime_3 , 0)) +
SUM(IF(PSLC.PSLC_CAUSALI.AvailableCausa_4 NOT LIKE ('%sezione%'),PSLC.PSLC_CAUSALI.AvailableTotTime_4 , 0)) +
SUM(IF(PSLC.PSLC_CAUSALI.AvailableCausa_5 NOT LIKE ('%sezione%'),PSLC.PSLC_CAUSALI.AvailableTotTime_5 , 0)) +
SUM(IF(PSLC.PSLC_CAUSALI.AvailableCausa_6 NOT LIKE ('%sezione%'),PSLC.PSLC_CAUSALI.AvailableTotTime_6 , 0)) +
SUM(IF(PSLC.PSLC_CAUSALI.Causa_1 NOT LIKE ('%sezione%'),PSLC.PSLC_CAUSALI.Total_Time_1 , 0)) +
SUM(IF(PSLC.PSLC_CAUSALI.Causa_2 NOT LIKE ('%sezione%'),PSLC.PSLC_CAUSALI.Total_Time_2 , 0)) +
SUM(IF(PSLC.PSLC_CAUSALI.Causa_3 NOT LIKE ('%sezione%'),PSLC.PSLC_CAUSALI.Total_Time_3 , 0)) +
SUM(IF(PSLC.PSLC_CAUSALI.Causa_4 NOT LIKE ('%sezione%'),PSLC.PSLC_CAUSALI.Total_Time_4 , 0)) +
SUM(IF(PSLC.PSLC_CAUSALI.Causa_5 NOT LIKE ('%sezione%'),PSLC.PSLC_CAUSALI.Total_Time_5 , 0)) +
SUM(IF(PSLC.PSLC_CAUSALI.Causa_6 NOT LIKE ('%sezione%'),PSLC.PSLC_CAUSALI.Total_Time_6 , 0))),0), ',' , '.') as tempi,
#a := SAMPLE.products.vel_linea as Vel,
REPLACE(FORMAT(((#xxx * #a) / #l_spezz) ,0), ',' , '.') as MinFermoInPezzi
FROM PSLC.PSLC_Prod
JOIN PSLC.PSLC_CAUSALI ON (
(PSLC.PSLC_Prod.SezioneID = PSLC.PSLC_CAUSALI.IDSezione) and
(PSLC.PSLC_prod.giorno = PSLC.PSLC_CAUSALI.DataStartPrg) AND (
(PSLC.PSLC_prod.Cod_Spezz_1 = PSLC.PSLC_CAUSALI.IDSpezzone) OR
(PSLC.PSLC_prod.Cod_Spezz_2 = PSLC.PSLC_causali.IDSpezzone) OR
(PSLC.PSLC_prod.Cod_Spezz_3 = PSLC.PSLC_causali.IDSpezzone) OR
(PSLC.PSLC_prod.Cod_Spezz_4 = PSLC.PSLC_CAUSALI.IDSpezzone) OR
(PSLC.PSLC_prod.Cod_Spezz_5 = PSLC.PSLC_causali.IDSpezzone) OR
(PSLC.PSLC_prod.Cod_Spezz_6 = PSLC.PSLC_causali.IDSpezzone) ) AND
PSLC.PSLC_prod.ID_Prog = PSLC.PSLC_CAUSALI.ID_Prog)
JOIN sample.products ON (
PSLC.PSLC_Prod.SezioneID = sample.products.sku)
WHERE (PSLC.PSLC_Prod.giorno BETWEEN '2014-05-05' AND '2014-05-09') AND
(PSLC.PSLC_Prod.SezioneID = PSLC.PSLC_CAUSALI.IDSezione) AND (
((PSLC.PSLC_prod.Cod_Spezz_1 = #cod_spezz) OR
(PSLC.PSLC_prod.Cod_Spezz_2 = #cod_spezz) OR
(PSLC.PSLC_prod.Cod_Spezz_3 = #cod_spezz) OR
(PSLC.PSLC_prod.Cod_Spezz_4 = #cod_spezz) OR
(PSLC.PSLC_prod.Cod_Spezz_5 = #cod_spezz) OR
(PSLC.PSLC_prod.Cod_Spezz_6 = #cod_spezz))
)
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)