I have the following query with me:
SELECT T1.C1,
CAST((SUM(1) OVER (ORDER BY T1.C2 ROWS UNBOUNDED PRECEDING) + T2.C3 (FORMAT '--(37)9') AS VARCHAR(20) )) AS RESULT
FROM
T1
CROSS JOIN
T2;
What would be the equivalent for (FORMAT '--(37)9') in Azure Synapse Analytics?
This is a really weird query (including SUM(1) instead of COUNT(*))
It's returning an integer as a left aligned string.
Unless T2.C3 is a decimal with fractional digits you can simply remove the FORMAT and CAST to VARCHAR(20).
If T2.C3 has a fraction, CAST to BIGINT or DECIMAL(38,0) first.
Related
in snowflake the number data type supports 38 digits length.
to store the values more than 38 digits ,i have used the varchar data type.
I have two set of tables ,
table1:
Block varchar
numberstart varchar
numberend varchar
table2
number varchar
i want see the block details from table1 where table2.number exist between table1.numberstart and table2.numberend
here i have two issues
string comparison giving wrong output.
i can not convert it into number using cast or to_number function, because the string values are more than 38 digits.
You could LPAD values to common size and then perform string comparison
SELECT*
FROM table2 t2
JOIN table1 t1
ON LPAD(t2.number, 50, '0') BETWEEN LPAD(t1.numberstart, 50, '0')
AND LPAD(t1.numberend, 50, '0');
db<>fiddle demo
It is simplified case, if negative numbers or fractions are involved it will not work.
I am trying to convert bigint to scientific number in hive using cast function as below
select cast(805454539 as float) from table name;
Above query is giving me 805454528
However, I am looking for something like 8.05454539E8
To convert float to scientific notation string representation you can use printf() function (8 in this example - is the number of decimal places):
select printf('%1.8e',cast(805454539 as double))
result:
8.05454539e+08
I need to create a computed column in SAS with the combination of the string 'ULPDT_' and the result from the today() function. so that my result looks like this: ULPDT_20190101. Here is my non-functional code for the advanced expression:
t1.SourceFile='ULPDT_'||PUT(today(), yyddmmn8.)
year-day-month, YYYYDDMM, is not a normal representation for date, you might actually want year-month-day YYYYMMDD
t1 is indicative of an EG generated join wherein the t1 is a table alias. If you are editing the code of a join node, and the problematic statement is part of a select clause, the correct SQL syntax might be
'ULPDT_'||PUT(today(), yymmddn8.) as t1.SourceFile
Hand coded example (versus EG visual join):
proc sql;
create table x as
select
'ULPDT_'||PUT(today(), yymmddn8.) as SourceFile
from
sashelp.class(obs=1)
;
i am stuck with the scenario where i have to sort
'a-2.3'
'a-1.1' and
'a-1.02'.
how do we do this using jpql in spring data jpa or using sql query. I would appreciate your personal experience and idea.
the sorting expected in ascending order based on the numerical value after a- .
This will depend on the database you're using, but e.g. in Oracle, you could call TO_NUMBER(SUBSTR(col, 3)) with SQL:
WITH t (col) AS (
SELECT 'a-2.3' FROM dual UNION ALL
SELECT 'a-1.1' FROM dual UNION ALL
SELECT 'a-1.02' FROM dual
)
SELECT col
FROM t
ORDER BY to_number(substr(col, 3))
This yields:
a-1.02
a-1.1
a-2.3
Of course, you'll have to adapt the parsing in case your prefix isn't always exactly a-, but something dynamic.
In JPQL, this could be feasible: CAST(SUBSTRING(col, 3, LENGTH(col) - 2) AS NUMBER)
I have a few things I want to accomplish with Presto. I currently getting some data in the following formats
date 16-Jan-2018
num 1000
I want to write a query that can convert these values to
2018-01-16
1,000
For the date you could do the following:
select date_parse('date 16-Jan-2018','date %d-%b-%Y')
For the second field, you would have to split it first with split(string, delimiter), then cast the second array element to INTEGER.
Here is the full answer:
SELECT date_parse(date_string,'date %d-%b-%Y') as parsed_date,
CAST(
split(int_string, ' ')[2] AS INTEGER
) as parsed_int
FROM (VALUES ('date 16-Jan-2018', 'int 1000'))
AS t(date_string, int_string)