SQL Division shows as null in SSRS - sql

I am trying to do some divisions in SQL and put them into an SSRS table object.
This SQL works, and the result is 0.6:
select testcol2/5 testcol from (select 3 testcol2 from dual)
But when i try to do the other way around (so divide with the column) the SSRS table shows no value instead of 1.6:
select 5/testcol2 testcol from (select 3 testcol2 from dual)
Please can someone help me how to get SSRS to show me the 1.6 value?

This is pretty strange, but I was able to reproduce it. When I run the SQL in a different tool, I can confirm that the result is 1.666666..., but SSRS isn't displaying it.
Here is a solution that works. Change the SQL to round the result:
select ROUND(5/testcol2, 2) as testcol2
from (select 3 testcol2 from dual)
Now SSRS will display 1.67 as expected. And it will honor any additional number formatting that you place on the textbox as usual.
Edit:
To satisfy my curiosity, I dug in a little more. I used the dump function in Oracle to determine that it was using a length of 193. This works if you round with up to 28 decimal places. Anything more than that and SSRS won't display the value.

Related

Convert Xpath to SQL

Previously we were fetching a number of countries from a table. Now the table changed to support multiple languages inside the text cell. The previous SQL statement was:
select b.text, a.iso_num, a.iso2, a.iso3, a.kfz, a.ind_member
from schema.zl_countrycode a, schema.zl_countrycode_lsd b
where a.ind_land = 1 and a.kfz is not NULL and dat_end = to_date('99991231','YYYYMMDD') and a.ZL_COUNTRYCODE_id = b.ZL_COUNTRYCODE_LSD_ID order by text
The list previously outputted each country in a row.
With the addition of the language selection, the list suddenly doubled in size - because it lists every county in two different languages.
This is how the table looks with the GUI
I'm trying to figure out, how to expend the statement to only select each "DE:" value in the text column. After having a quick indirect discussion with the developers, they provided me this XPATH statement:
Parentofparent/Parent/Valuestable[name="ZL_COUNTRYCODE"]/Valueclassification[name="TEXT"]/Value/ValueLng[lng="DE"]
I don't know the first thing about XPATH and no matter what I have tried so far, it failed.
Please help me out if you're knowledgeable in this field. It's probably an Oracle database, as I have experienced a plethora of Oracle error codes in the last few days.
I think this should do the trick:
SELECT b.TEXT
,a.iso_num
,a.iso2
,a.iso3
,a.kfz
,a.ind_member
,a.de
FROM SCHEMA.zl_countrycode a
JOIN SCHEMA.zl_countrycode_lsd b
ON a.ZL_COUNTRYCODE_id = b.ZL_COUNTRYCODE_LSD_ID AND b.spec_lng = 'DE'
WHERE a.ind_land = 1
AND a.kfz IS NOT NULL
AND dat_end = to_date('99991231', 'YYYYMMDD')
ORDER BY TEXT

Redshift SQL WHERE statement doesn't seem to filter correctly?

So I have a pretty simple query something like:
Select * from TableX where column1 = '2020-24'
However, in the results we get column 1 but it is not restricted to 2020-24 (week 24 in 2020), I see 2020-20 and 2020-05 etc.
I assume it's something to do with text/number formatting or something. I am using Redshift SQL, how can I fix this so it only shows rows where column 1 is '2020-24'? I tried use the WHERE with 2020-24 and with '2020-24' but both give the same result. I have heard I may need to cast with :: notation but not sure how..

BigQuery/I can't correctly result using "in" clauses

I want to extract perfectly match data, not partical match data.
But, I can't extract them, if I execute sql code of the below:
I estimate this sql code extract no data , but this extract all rows of data.
【SQL code】
WITH a AS(
SELECT
001 AS id_a,
112345678901234567 AS x
UNION ALL
SELECT
002,
112345678901233567
UNION ALL
SELECT
003,
112345678901232568
),
comp_a AS(
SELECT
*
FROM
a
WHERE
x IN(112345678901234000, 112345678901233000, 112345678901232000)
),
comp_b AS(
SELECT
004 AS id_b
UNION ALL
SELECT
005
)
SELECT
id_a,
id_b
FROM
comp_a
LEFT OUTER JOIN
comp_b
ON (
comp_a.id_a = comp_b.id_b
)
WHERE
comp_b.id_b IS NULL
;
I think "in" clauses are used for perfectly match.
But, perhaps, I think this sql code isn't executed "in" clauses , but it is executed "like" clauses.
I will be glad you answer solution of my question.
■Further note:
 ・I deleted cashe of browser and Bigquery. But I couldn't solve it.
 ・This sql code is sample code , because I can't expose real sql code.
・I can recreate this problem in One enviroment of BigQuery,
but I can't recreate in Other enviroment of BigQuery.
This Problem may be not problem of sql code , but problem of enviroment
or setting.
Thank you for answering my question.
I solved my question.
The cause of my problem is not BigQuery , but it is the format of Excel.
Detail:
I tried to check data using Excel , Because the results are a lot of data.
Sad to say , Because of the format of Excel is numeric type , a part of number data are rounded. So I misunderstood the correct result to the wrong result.
Sorry about my misunderstanding.

SQL Server floating point numbers

I was wondering if there is a way to show the values of columns of type floating point numbers in two decimal places in SQL Server 2008 via settings? For instance, let say I have a table called orders with several columns. I want to be able to do the following:
SELECT * FROM orders
I expect to see any values in columns of type float to display with decimal notation; for instance, a value of 4 should display as 4.0 or 4.00.
Thanks
You may use CONVERT function with NUMERIC( x , 2) for numeric values
( where x is at least 3, better more, upto 38 )
SELECT CONVERT(NUMERIC(10, 2), 4 ) as "Dcm Nr(2)";
Dcm Nr(2)
---------
4,00
SELECT CONVERT(NUMERIC(10, 1), 4 ) as "Dcm Nr(1)";
Dcm Nr(1)
---------
4,0
The simplest form of what happens to me is making a "cast", for example:
SELECT CAST(orders AS DECIMAL(10,2)) FROM [your table];
The short answer to your question is "No".
SQL Server isn't really in the business of data presentation. We all do a lot of backbends from time to time to force things into a presentable state, and the other answers provided so far can help you on a column by column basis.
But the sort of "set it and forget it" thing you're looking for is better handled in a front end application.

Oracle TO_CHAR Format Mask for displaying both integral numbers and floating point numbers

I'm trying to find the correct Oracle format mask to display numbers on an Apex page in a report in a certain way.
Most of the times these numbers are integers but sometimes these numbers can be floating point numbers.
Let's say I have the following three queries:
Query 1
SELECT TO_CHAR(1, '<Format Mask>', 'NLS_NUMERIC_CHARACTERS = '',.''') FROM DUAL;
Query 2
SELECT TO_CHAR(0.1, '<Format Mask>', 'NLS_NUMERIC_CHARACTERS = '',.''') FROM DUAL;
Query 3
SELECT TO_CHAR(0.01, '<Format Mask>', 'NLS_NUMERIC_CHARACTERS = '',.''') FROM DUAL;
Now I want to use one single format mask which will give me the following results:
Result 1
1
Result 2
0,1
Result 3
0,01
Can anyone provide me with the correct format mask to achieve this?
I've tried a format mask like FM990D999 but it leaves me with a comma trailing the 1 in Query 1.
There are ways to alter your column value in the query while still retaining (some) of the functionality in the report(s). However, having multiple such columns and multiple report you might find there is a lot of overhead for little gain.
Look at this post on the OTN forums: order by date in IR
The issue is much the same: the data in the column represents a date but is actually not a date. This post contains a solution to use in apex < 4.2.
From 4.2 onwards you have a better option called the HTML expression.
Again, linked from OTN: Re: Report formatting/sorting issue
Quoted from linked post, user fac586
Include both variance and abs(variance) in the query:
SELECT
region,
estimate,
actual,
(estimate - actual) AS variance,
ABS(estimate - actual) AS abs_variance,
(CASE
WHEN (estimate - actual)>=0 THEN 'green'
WHEN (estimate - actual)<0 THEN 'red'
ELSE NULL
END) AS variance_color
from
expenses
And the HTML Expression for the "variance" column is:
<span style="color: #VARIANCE_COLOR#; font-weight: bold;">#ABS_VARIANCE#</span>
Hide the #VARIANCE_COLOR# and #ABS_VARIANCE# columns.
#ABS_VARIANCE# is the value shown in the column, but the sort is
performed in the underlying SQL using the original variance value.
This is much like Alex suggested but is a bit more work: formatting in the source, adding an html expression, hiding the other column.
I suppose it depends on how far you want to drive it. Why not just apply the format to the column through its attributes?
Also be aware it is possible to use string substitution syntax in those fields. You could have a couple application items containing format masks, and then reference the correct mask in the format mask field.
Eg:
Application item AI_FORMAT_MASK1 has a value FM9990D00.
In the format mask field you can then use &AI_FORMAT_MASK1.