Handle divisor 0 error when some divisors are NULL - tsql

I am getting dividing by 0 errors. I noticed that sometimes the field I'm dividing by is NULL.
(SUM(RentMonths * SQFT) / SUM(SQFT))
What's the proper way to handle this situation when SQFT can be null at times? I know it's probably bad data but that's besides the point; I can't fix that right now.

Dividing by NULL is perfectly valid - the result is simply NULL. The problem is (as the error message states) when you try to divide by zero.
You can use NULLIF to solve this problem:
(SUM(RentMonths * SQFT) / NULLIF(SUM(SQFT), 0))
The result will be NULL if the divisor is 0 or if either operand is NULL.
As pointed out in the comments, a CASE statement could also be used:
CASE WHEN SUM(SQFT) <> 0 THEN (SUM(RentMonths * SQFT) / SUM(SQFT)) END
The advantage is that this will work in almost any database, but a disadvantage is that it repeats the expression to calculate the divisor.

An IF statement seems pretty appropriate here, no?
Don't know if this is correct TSQL syntax but:
IF #SQFT IS NOT NULL (SUM(RentMonths * SQFT) / SUM(SQFT))

Related

Check if num is between two double value - Dart

Why can't you do this if you try to find out whether an int is between two numbers:
if (16.5 < value < 17.5)
Instead of it, you'll have to do
if (value > 16.5 && value < 17.5)
which seems like a bit of overhead.
short answer
you can make own method like
between(value, 1, 10);
long answer
you have to think about how the compilor works.
first. they have a some kind of parser that reads program language.
if you write 'if' conditional. a parsor read 'i' and 'f' character. then expect '(' sign.
if ( a > b )
check value, check sign, check value again, and check ')' sign.
The program then knows that this is a conditional statement. then make machine code like 01010101(idk. but we can't read something).
In this fomular. Finally comparing the values ​​is one by one(The compiler will work in the smallest unit possible).
Efficiency is very important at this stage. come back your code.
if (16.5 < value < 17.5)
and how about this?
if (16.5 < value > 17.5)
and how about?
if (16.5 > value < 17.5)
this is have many exception. But dart might be able to make this syntax. but they won't.
Because they too have to do the work of comparing one by one.
so you can make own method.
Try the following code:
if (value.clamp(16.6, 17.4) == value) {
// Do what you want to do
}
I think the .clamp function is to check if a number is less than the lower bound (16.6) or greater than the upper bound (17.4) or between the lower bound and the upper bound. If the number is less than the lower limit or greater than the upper limit, then display the lower or upper limit, otherwise display the number (I know by testing in DartPad)

Tablix Expressions (Multiple Condition)

I'm currently experiencing
The Value expression for the textrun ‘Textbox137.Paragraphs[0].TextRuns[0]’ contains an error: [BC30198] ')' expected.
=(Variables!Seconds.Value <= 500,"PASS", "FAIL") OR (Variables!Seconds.Value < 0,"N/A","")
This is a results column. In event that seconds is negative number it will be N/A. which means anything less then 0.
any thoughts on my syntax.
Not really sure where to begin with this as the syntax is almost entirely wrong, unfortunately. From my best inference, I am guessing you want N/A if less than 0, PASS if less than or equal to 500, and FAIL for anything above that. I'm also not sure why you're using variables rather than populating your data with a query and using the Fields!... syntax, but that's another issue entirely. To fix your current issue, you've neglected to include the IIF function that you seem to be trying to use. I think the expression you'll want is the following.
=IIF(Variables!Seconds.Value < 0, "N/A", IIF(Variables!Seconds.Value <= 500, "PASS", "FAIL"))
This will first check the variable to see if it is less than 0, printing N/A if so. If false, it will evaluate the second IIF that will print PASS for less than 500 and FAIL for anything above 500.

SAP Unicode: Offset exceed

I got some account issues in the SCN so I make a attempt here.
We switched to Unicode and got some issues with that. INFTY_TAB = PS+2. This coding gets an error that "the offset + length is exceeding".
I found some hints but couldn't really figure out how to fix this. And even when I manage to fix those errors I got a new error called 'Iclude-Report %HR_P9002 not found'. The IT is still there so is there something else I can check?
Definition of PS:
DATA: BEGIN OF PS OCCURS 0.
*This indicates if a record was read with disabled authority check.
data: authc_disabled(1) type c.
DATA: TCLAS LIKE PSPAR-TCLAS.
INCLUDE STRUCTURE PRELP.
DATA: ACRCD LIKE SY-SUBRC.
DATA: END OF PS.
TCLAS is a char(1) field.
This is the part where the error pops up:
INFTY_TAB = PS+2.
Error: I had to translate so sorry for some mistakes that could appear.
Offset and Length (=2432) exceed the length of the character based beginning (=2430) of the structure.
Depends on the length of INFTY_TAB. You have to explicitly set length:
INFTY_TAB = PS+2(length).
Official information is here. The important point to note is that the inclusion of SY-SUBRC (which is an INT4 field) places a limit to the range of fields you can access using this (discouraged) method of access.
ASSIGN field+off TO is generally forbidden from a syntactical
point of view since any offset <> 0 would cause the range to be
exceeded.
Although the sentence above is related to ASSIGN command, it is also valid for this situation.

Mupad cast boolean to integer

I give a simple example of what I want to do in Matlabs MuPad
S := matrix([[0,S_1,S_2]]);
sum(S[k]*(k < 2)* S[k] * (TRUE), k=1..3)
should be: "S_1^2 + S_2"
however I get: Error: The first argument must be of type 'Type::Arithmetical'. [sum]
I understand the error, I just don't know how to succeed.
Advice appreciated. I'm looking for some kind of indicator function.
The question:
Start with the inner term. To have a valid number 0 or 1, I used the following expression:
piecewise([A[k]>a*B[l],1],[Otherwise,0])
The rest is straight forward:
sum(sum(A[k]*B[l]*piecewise([A[k]>a*B[l],1],[Otherwise,0]), l=1..L), k=1..K)
S := matrix([[0,S_1,S_2]]);
sum(S[k]^(4-k), k=1..3)
I'm to really sure what you are trying to do.

Why can I not store 16 bits in a logic in SystemVerilog?!

I am currently having issues when trying to store a 16bit number coming from the input of my module into one of my logic variables. When I set all the bits high in my test bench I get a value: 0000000000000001. Hope you can help! PS: Sorry, dont know how to insert code on here....
My code is shown below:
http://pastebin.com/cZCYKJqV
I think your problem is likely with this line:
regy = (!regy)+1;
regy is a 16-bit value. Using the negation operator (!) on a multi-bit value is equivalent to (value != 0). So for any value of regy other than zero will set regy to 1.
If you are trying to invert all the bits and add 1, you need to use the ~ operator.
Example:
regy = (~regy)+1;