I'm using SQL Server 2008 R2, SSAS Enterprise edition.
I want to know please how to convert negative values in my calculated measure into 0.
Thanks!
Galshan
If you want to really show negative values as zero, then use something like
IIf(your_expression < 0, 0, your_expression)
where your_expression is the expression to calculate your expression. You could also use the format_string of the calculated measure to keep the value as it is, but just display it to users as zero, provided the client tool they use honors the format_string or formatted_value. The format string would be something like
'#;0'
See http://technet.microsoft.com/en-us/library/ms146084(v=sql.105).aspx for details of the format_string.
Related
In my Metabase, I wrote a query SELECT 10/5 It showing a result 2.000000000 which is correct.
But When I wrote SELECT 5/10 It showing a result 0.000000000. The result should show 0.500000000.
Can you explain it? Why divide function is not working?
Metabase can parse SQL different ways. It depends on connector type.
But in most cases, the result depends on the data type.
Your example uses integer division, because both of operands are integer.
You can just try to change the data type
It is rounding off the value,
Like for select 7/5 it will print 1.
If i have a column with datatype decimal(p,s) what is the standard for expected result's precision and scale when i execute average aggregate.?
i.e result = select avg(decimal(p,s)) from table1;
what is must be the result decimal precision and scale.?
Some links from existing databases like
1. https://docs.oracle.com/javadb/10.6.2.1/ref/rrefsqlj36146.html#rrefsqlj36146
2. https://learn.microsoft.com/en-us/sql/t-sql/functions/avg-transact-sql?view=sql-server-2017
But unable to see any standard followed here. So is there a well accepted standard of this in sql or is it always implementation basis.?
Personally not aware of a standard, have always adjusted based on the level of detail that is required of the column.
I'm not using SQL at this point, I'm just trying to define a function using query design function in MS Access 2010.
What i'm trying to do:
So turns out that I have a 5 month spread (Jan,Feb..May) where each month is a column. Turns out that at times May has a value and January does not, but it should. All the values are either one or null.
What I'm trying to do is write an if function of this sort:
Jan15new: Iff([May-15]=1,[Jan-15]=1,[Jan-15])
However, when I run the query with this iff function I got a column full of negative ones that doesn't abide by the rules of this if function.
If you can shed somelight that would be great!
thanks,
This formula returns a 1 if May-15 = 1, otherwise returns whatever value is in Jan-15:
Jan15new: IIf([May-15]=1,1,[Jan-15])
If the values in your formula are Boolean values, you do not need to compare them to anything, and you should not be comparing them to numbers:
Jan15new: IIf([May-15]=True,[Jan-15]=True,[Jan-15])
That's actually meaningless, because it is equivalent to this:
Jan15new: IIf([May-15],[Jan-15],[Jan-15])
I need to do some very precise reporting in SQL Server Reporting Services. I'm actually attempting to show 13 decimal places. The odd part is even when I format the field C13, Reporting Services seems to round after an arbitrary number of total digits rather than anything to do with the format string.
For example if I have:
1000.01234567890123
What I end up with is:
1000.0123456789000
If on the other hand I have:
10.01234567890123
What I end up with is:
10.01234567890100
So it appears that I only end up with 15 actual digits from my source number. Has anyone seen this before, or know how to resolve it?
It sounds to me like you are using the Float datatype. Instead, I would suggest you use the decimal data type instead. You'll probably want to use something like Decimal(20, 14). You'll still need to be very careful about the math you perform because SQL Server will modify the resulting data type when you perform math on decimals.
Actually, I found the problem was Microsoft's Double.ToString() method. I had to use a "G13" as a formatting string to get all of the decimal places. Go figure.
I have Decimal field in SQLserver 2005 table,
Price decimal(18, 4)
if I write 12 it will be converted to 12.0000, if I write 12.33 it will be converted into 12.3300.
Always it's putting zero to the right of the decimal point in the count of Scale Part(4).
I was using these in SQL Server 2000, it was not behaving like this, in SQL Server 2000 if I put 12.5 it will be stored as 12.5 not as 12.5000 what SQLServer2005 do.
My Question is how to stop SQL Server 2005 from putting zeros to the right of the decimal point?
SQL Server 2000 also have stored the value to to 4 decimal places too with trailing zeros.
What you are seeing is how the client tools present it.
decimal (18,4) behaves the same in both versions... otherwise it would be float/real
Edit, after comment:
The data type passed to your client code is always decimal and behaviour will not change. Whether you have format strings or not does not matter to the SQL data type. The behaviour of the data type is unchanged between versions.
I'm only saying the the SQL client tools show the value differently.
If your application displays differently then the data types are different: it is as simple as that.