SSRS Overload resolution failed because no accessible 'IIf' accepts this number of arguments - reporting-services

I wrote a formula using the values of other textboxes in a textbox, but the system does not accept it. The formula is as below
=IIF(ReportItems!Textbox66.Value>=1,IIF(ReportItems!Textbox257.Value>=500,CInt((ReportItems!Textbox66.Value*100-100)/5),IIF(CInt((ReportItems!Textbox66.Value*100-100)/5)>=4,4,CInt((ReportItems!Textbox66.Value*100-100)/5))),IIF(ReportItems!Textbox257.Value<500,IIF(CInt((100-ReportItems!Textbox66.Value*100)/5)>-4,-4,IIF((100-ReportItems!Textbox66.Value*100)/5*(-1))),(CInt((100-ReportItems!Textbox66.Value*100)/5*(-1)))))

It looks like there's an IIF statement with only one of the three arguments.
IIF((100-ReportItems!Textbox66.Value*100)/5*(-1))
It should have an argument for the value when the IIF expression is True of False.
IIF((100-ReportItems!Textbox66.Value * 100) / 5 * (-1), ?, ?)
It's easier to find if you use returns and tabs to break up the expression. A few spaces don't hurt either.
=IIF(ReportItems!Textbox66.Value >= 1,
IIF(ReportItems!Textbox257.Value >= 500,
CInt((ReportItems!Textbox66.Value * 100 - 100) / 5),
IIF(CInt((ReportItems!Textbox66.Value * 100 - 100) / 5) >= 4,
4,
CInt((ReportItems!Textbox66.Value * 100 - 100) / 5)
)
),
IIF(ReportItems!Textbox257.Value<500,
IIF(CInt((100 - ReportItems!Textbox66.Value * 100) / 5) > -4,
-4,
IIF((100 - ReportItems!Textbox66.Value * 100) / 5 * (-1), ?, ?)
),
CInt((100 - ReportItems!Textbox66.Value * 100) / 5 * (-1))
)
)
It might be a bit more tedious to use a SWITCH but it may be easier to read and make it work the way you want.
=SWITCH(ReportItems!Textbox66.Value >= 1 AND ReportItems!Textbox257.Value >= 500, CInt((ReportItems!Textbox66.Value * 100 - 100) / 5),
ReportItems!Textbox66.Value >= 1 AND CInt((ReportItems!Textbox66.Value * 100 - 100) / 5) >= 4, 4,
ReportItems!Textbox66.Value >= 1, CInt((ReportItems!Textbox66.Value * 100 - 100) / 5),
ReportItems!Textbox257.Value < 500 AND CInt((100 - ReportItems!Textbox66.Value * 100) / 5) > -4,
-4,
ReportItems!Textbox257.Value < 500 AND (100 - ReportItems!Textbox66.Value * 100) / 5 * (-1) = ?????, ?????,
ReportItems!Textbox257.Value < 500, CInt((100 - ReportItems!Textbox66.Value * 100) / 5 * (-1))
)

Related

MySQL : UPDATE query and allows negative

The objective of this code is to deduct ringgit value and sen value in respective column and allows the value to be negative.
Assuming the price of item to purchase are RM1.50, and the users' balance are RM 0.80, RM 2.40 and RM -1.00.
The table should look like this :
Before purchase was made
Id
user
ringgit
sen
1
User A
0
80
2
User B
2
40
3
User C
-1
0
After purchase was made.
Id
user
ringgit
sen
1
User A
0
-70
2
User B
0
90
3
User C
-2
-50
I used code below to deduct user's balance. But the code only can deduct correctly if the user's balance is sufficient to purchase the item. (no negative value allowed)
UPDATE users SET ringgit = CASE
WHEN (sen - ".$senToDeduct." < 0) THEN (ringgit - ".$ringgitToDeduct." - 1)
WHEN (sen - ".$senToDeduct." >= 0) THEN (ringgit - ".$ringgitToDeduct.")
END,
sen =
CASE
WHEN (sen - ".$senToDeduct." < 0) THEN (100 - (".$senToDeduct." - sen))
WHEN (sen - ".$senToDeduct." >= 0) THEN (sen - ".$senToDeduct.") END WHERE Id = 1
I try to use code as follows :
UPDATE users SET ringgit =
CASE
WHEN (((ringgit * 100) + sen) - 150 >= 0) THEN LEFT(((ringgit * 100) + sen) - 150,char_length(((ringgit * 100) + sen) - 150)-2)
WHEN (((ringgit * 100) + sen) - 150 < 0) THEN - LEFT(((abs(ringgit) * 100) + abs(sen) - 150),char_length(((abs(ringgit) * 100) + abs(sen) - 250))-2)
END,
sen = CASE
WHEN (((ringgit * 100) + sen) - 150 >= 0) THEN RIGHT(((ringgit * 100) + sen) - 150,2)
WHEN (((ringgit * 100) + sen) - 150 < 0) THEN - RIGHT(((abs(ringgit) * 100) + abs(sen) - 150),2)
END
WHERE Id = 1
..but it does not work as the ringgit column already got affected after the query run SET ringgit =

MySQL - MOD() return 1 instead of 0

I have the following MySQL code that according to me should return 0:
mod( mod((180 / (30.4166666667 * 24 * 60)),1) * 30.4166666667,1) * 24 as HoursWorked
=> return 3.000
mod(mod(mod((180 / (30.4166666667 * 24 * 60)),1) * 30.4166666667,1) * 24,1) as ModHoursWorked
=> return 1
What am I missing?
the division must be floored
select mod(mod(mod(( floor(180 / (30.4166666667 * 24 * 60)) ),1) * 30.4166666667,1) * 24,1) ;
This worked:
SELECT truncate(mod(mod(mod((180 / (30.4166666667 * 24 * 60)),1) * 30.4166666667, 1) * 24, 1), 0) AS ModHoursWorked; => return 0

Mysql : Use IF in TRUNCATE

This is the query, simplified.
SELECT `a`, TRUNCATE(`b` / 1000, 3) AS `b`
FROM (
...
) AS `m`
GROUP BY `a`
ORDER BY `a`
What i'm trying to do is change the number of decimal places (actual 3) based on the value of b.
So i tried this:
SELECT `a`, TRUNCATE(`b` / 1000, IF(`b` < 10, 2, 3)) AS `b` ...
and this
SELECT `a `, IF(`b ` < 10, TRUNCATE(`b ` / 1000, 2), TRUNCATE(`b ` / 1000, 3)) AS `b `
If b is less than 10, i want 3 decimal places, otherwise 2.
But this doesn't seem to work ...
Resources : https://dev.mysql.com/doc/refman/8.0/en/control-flow-functions.html#function_if
just change the values position that you put in your query
SELECT `a `, IF(b < 10, TRUNCATE(b / 1000, 3), TRUNCATE(b / 1000, 2))
AS b
if(a<1,2,3) means if a<1 then 2 will come as a value in your result so you have to switch your values position
use round
SELECT a , IF(b < 10, round((b / 1000), 2), round((b / 1000), 3) ) AS b
The ROUND() function rounds a number to a specified number of decimal places.
example SELECT ROUND(345.156, 2); result = 345.16
SELECT ROUND(345.156, 2); result = 345.156
If you don't want round then TRUNCATE will shown 0.00 in case of b value less than 10, so what do you mean by not working ?
You need 3 decimal place when b<10 so you have to change the position of yours query result
You have misplaced the order of queries to run, in case of true/false evaluation in If(). Following may work:
SELECT `a `,
IF(`b ` < 10,
TRUNCATE(`b ` / 1000, 3),
TRUNCATE(`b ` / 1000, 2)
) AS `b `

PostgreSQL - column doesn't exist (WHERE with AS)

i am a bit newbie to PostgreSQL, but i have a few experiences with MySQL.
The Postgres is showing me and error - COLUMN doesn't exist, but this is a "virtual column", created by AS.
Code, which is working very well in MySQL:
SELECT place.*, 3956 * 2 * ASIN(SQRT( POWER(SIN((place.lattitude - $1) * pi() / 180 / 2), 2) + COS($2 * pi() / 180) * COS(place.lattitude * pi() / 180) *POWER(SIN(($3 - place.longitude) * pi() / 180 / 2), 2) )) AS "distance" FROM place WHERE place.longitude BETWEEN $4 AND $5 AND place.lattitude BETWEEN $6 AND $7 HAVING "distance" < $8 ORDER BY "distance" LIMIT 10
But Postgres is showing Column "distance" does not exist.
How can I rewrite it? (Please write full SQL query, not "How to")
$number is variable (against SQL injection)
Thanks
Use a subquery:
SELECT p.*
FROM (SELECT place.*, 3956 * 2 * ASIN(SQRT( POWER(SIN((place.lattitude - $1) * pi() / 180 / 2), 2) + COS($2 * pi() / 180) * COS(place.lattitude * pi() / 180) *POWER(SIN(($3 - place.longitude) * pi() / 180 / 2), 2) )) AS "distance"
FROM place
WHERE place.longitude BETWEEN $4 AND $5 AND
place.lattitude BETWEEN $6 AND $7
) p
WHERE "distance" < $8
ORDER BY "distance"
LIMIT 10;
You don't want to use a subquery in MySQL because it materializes the intermediate result. Other databases are smarter in how they optimize queries, and do not necessarily materialize subqueries.

How to pass from seconds to time

How can I pass from seconds to time on mysql?
the date format of out is hh:mm:ss.ms
Sorry. I need for example 0.98 sec -> 00:00:00.980; With sec_to_tiem return 00:00:01.
thanks.
I have implemeted of this way:
select concat(if(floor(seconds/(60 * 60)) = 0,'00',lpad(floor(seconds/(60 * 60)),2,'0')),
':',
if(floor(seconds/60) = 0,'00',lpad(floor(seconds / 60),2,'0')),
':',
seconds % 60)
but it have to exist other way more efficient
other way:
CONCAT(lpad(floor(seconds / 3600), 2, '0'), ':',
lpad(floor(seconds / 60), 2, '0'), ':',
lpad(floor(seconds % 60), 2, '0'), '.',
lpad(SUBSTRING_INDEX((seconds * 1000) % 1000, '.', 1), 3, '0'))
SELECT MAKETIME (<yourseconds>/(60*24), <yourseconds>/60, <yourseconds>%60)
or with format
SELECT TIME_FORMAT( MAKETIME( <yourseconds>/ ( 60 *24 ) , <yourseconds>/60, <yourseconds>%60 ) , '%T.%f' )