Convert 10 digit number from Legacy system to Date in SQL - sql

I am converting data from a legacy system to SQL. I got to convert a 10 digit number (e.g. 1419120000) to SQL DateTime. I am able to do so using dateadd(second,1419120000,'1970-01-01'). This function returns '2014-12-21 00:00:00.000'. However, in the UI of the legacy system it shows '12/20/2022' for the same value. So, the mentioned number (1419120000) supposed to be '12/20/2022'.
Can anyone please help me to get '12/20/2022' from 1419120000.

Related

Teradata handling single digit month and day problem

I have below values coming from a flat file which may contain single digit month & day field:
9/14/2020 07:20:18.630000
7/7/2020 16:24:57.700000
10/24/2019 03:40:52.380000
11/9/2020 20:21:32.420000
Now I need to load this to a column having TIMESTAMP(6) as the data type.
Can someone please help on this? I am using TD SQL Assistant version 16.
SQL Assistant is not a load utility, e.g. TPT fully supports dealing with intput like this.
Your other post shows that you already use a RegEx to add the missing zeroes and you apply the correct format. This is indicating bad data in your input. You might try to spot the error in the input file (check how many rows have been loaded and check the following lines).
Or you apply TRYCAST which doesn't fail, but returns a NULL for bad dates. But yikes, it doesn't support FORMAT, thus you must rearrange the MDY to YMD first:
trycast(RegExp_Replace(RegExp_Replace(x,'\b([0-9])\b', '0\1'), '(..).(..).(....)(.*)','\3-\1-\2\4') as timestamp(6))

Format Phone Number SQL Server

I am working on a stored procedure that in part, pulls phone numbers from a database.
In some cases, the number may be in an incorrect format. The correct format is:
+714XXXXXXX, however there are cases where the number appears as, e.g: 142877261
or 7147267261. There are even some cases where the number appears as say, ++1749186372
How can i force the number to append +714 to the start while keeping the rest of the number intact?
Any help would be much appreciated.
You can take the 7 most right digits and unconditionnaly preprending +714
'+714' + right(phonenumber, 7)

DB2 SQL z/OS - variable equivalent of a hex constant

I'm trying to extract data (using SPUFI) from a DB2 table to a file, with one of the output fields converting a decimal field to the same format as a COBOL comp field.
So e.g. today's date (20141007) would be ..ëõ
The SQL HEX function converts 20141007 to 013353CF, and doing a SELECT of x'013353CF' gives me the desired result, but obviously that's a constant, I'm trying to find an equivalent function.
Basically an inverse of the HEX function.
I've come across a couple of suggestions using user defined functions. Problem is, we've only recently upgraded to DB2 10 and new function mode isn't enabled yet, which means I don't have access to any control functions in a UDF.
I suspect I'm out of luck, but wondering if anyone has any suggestions.
I appreciate this is completely the wrong tool for the job, and would be easier to just write a COBOL program to do it, but various constraints are preventing that. I'm limited to just SQL functions and possibly JCL).
I thought I had a solution using a recursive UDF to get around the lack of control functions, but that's not allowed either.

the resulting value is outside the range for the data type decimal/numeric(31/31)

I have a complex sql which has more than 1000 row so I can't paste it here. I am using derby in memory db. When ı run my sql I get this error : the resulting value is outside the range for the data type decimal/numeric(31/31).
How can I fix it? any idea?
you can use a truncate function... really your trouble is that your decimals are more that your precision.. for example.. if you hace a decimal (10,2) it means that you can hace until 2 decimals... (counting for your 10 in numbers), you cant use 123456789.123 beacause your number of digits are mor than decimal (10,2)... if you need more info you can visit this link. Link info decimal sql server

sql server 2008: bcp_sendrow, issue: invalid time format

I'm having a problem "Invalid time format" when I try to use bcp functions(bcp_sendrow/bind etc.) to insert into a table having a datetime column.
so as per googled examples, I populated a DBDATETIME structure, for example: if I wanted to populate 3rd august 2009, exactly 8am localtime, I'd populate the structure members like so:
dtdays=40026(num days since 19000101) and
dttime = 28800000 (num millisecs since midnight)
(Also having bound the var. as a SQLDATETIME)
if dttime is 7 digits wide(or less), then bcp suceeds(but obviously with a wrong time value (date part is ok) )
how can I sort this out? I've tried datetime2 /time etc. but nothing helped.
please help , all advice/ideas most appreciated.
(I'm using Sql server 2008, and (ODBC) sql native client 10.0)
thanks!
never mind.. got it finally (sort of)
-DBDATETIME::dttime (num of millisecs since start of day) needs to be DIVIDED by 3.333333..
that way you get to the closest value to represent your time. (the field width is only 7 digits wide)..this probably has something to do with datetime type being able to represent only 1/3rd of a sec. accurately....
anyways, I tried using datetime2 with ODBC bcp api , but couldn't make the time part work
please let me know if anyone finds a better way
thanks!