Scientific notation in bigquery - google-bigquery

I have a source table with a column that stored as LEDGER_BAL_AMT as a String value, I have loaded this LEDGER_BAL_AMT as FLOAT in target table by using BIGQUERY.
When I query for this column I get it as a scientific notation like this:
6.2998225E7
But i need the output should be stored as FLOAT and the value like below
62998225.0

Try FORMAT: select FORMAT('%.1f', 6.2998225E7)

Related

Snowflake condition type on semi-structured data

In Snowflake I have a column that holds a semi-structured data that should hold numbers but as of semi-structured data nature, that is not strict. I want to check the type of data and convert to float if possible. Something like that:
SELECT IFF(TYPEOF(column_name::data_name) is NUMBER, column_name::data_name::FLOAT, null)
FROM some_table
How can I make this query work?
TRY_TO_DOUBLE is the tool you are looking for if you want it to be floating point. Otherwise if only Integer TRY_TO_NUMBER
SELECT try_to_double(column_name::data_name::TEXT)
FROM some_table
Here the DB doesn't like output of type VARAINT, which is what selecting a value from a VARAINT gives you. The way around this is turn it into a TEXT first:
SELECT
parse_json('{"data_name":3.14, "it_is_a_number":1234}') as column_name
,try_to_double(column_name:data_name::text) as dub
,try_to_number(column_name:it_is_a_number::text) as int
;
COLUMN_NAME
DUB
INT
{ "data_name": 3.14, "it_is_a_number": 1234 }
3.14
1,234

Commas using SAS and TD SQL

I am using SAS to pull data in a Teradata environment. I am counting the rows in the Teradata table, but want the output to be in a comma format (i.e. 1,000,000). I was able to use the code below to display the value as a comma, but when I try to add the column in SAS, I can't since the output is in a character format. Does anyone have any suggestions on how to format the number value as comma, so that it can be used for calculation purposes in SAS? Thanks.
CAST(Count(*) as (format 'Z,ZZZ,ZZ9')) as char(10)) as rowCount,
Assuming you're using pass through, pull it in as numeric and format it on the SAS side. You've now converted it to character (char10) and SAS doesn't do math on character variables which makes logical sense.
select rowCount format=comma12. from con
(select
count(*) as rowCount ....
)
If you have a select * you can always format it later in a data step or via PROC DATASETS. SAS separates the display and storage layers so the format controls the appearance but the underlying data still remains numeric.

CAST as Int working in Sybase whereas same doesn't displays output in Impala

I am trying to change the data type of a colum type string to int in imapala and show output, it doesn't work for Impala whereas it shows output in Sybased,
The dataset is same.
avg(cast(field to Int))

Represent versioned-number in Postgres

I have PostgreSQL 9.4 installed on my laptop and my database contains a versioned-number which has this format : A.B.C.D ( example : 1.2.13.6 ). How can i apply MAX aggregation to my column "version" which is text. Thank you very much
If the numbers are always numeric, you can do something like this:
select max(string_to_array(version, '.')::int[])
from your_table;
By converting the string into an array of integers, the comparison will be done correctly [1,12,1] is bigger than [1,1,1]
This will however fail if you have values like 1.2.13.6a in that column
SQLFiddle: http://sqlfiddle.com/#!15/d41d8/4608

multiple a bigint column and a decimal column in a table cell

I have a field of bigint and a field of decimal in data base and i would like to multiple those fields in a tablecell in reportingservices.
My code is like this:
(Fields!dpr_unitprice.Value) * (Fields!dpr_PurchasedQuntity.Value)
but the result is not correct.
How can i get the correct result?
It might be that your DB engine is returning a bigint.
Cast the bigint value as a decimal before multiplying the two.
You have to cast both fields to the unit you want to work with, so if you want to work with decimal then:
cdec((Fields!dpr_unitprice.Value)) * (Fields!dpr_PurchasedQuntity.Value)