I have to convert Trunc((FROM_TZ (TO_TIMESTAMP('2020-04-14','mm/dd/yyyy hh24:mi:ss'), 'GMT') AT TIME ZONE 'PST'),'dd') from Oracle to Snowflake.
Could anyone please help me with that.
Thanks in advance.
If you are looking for a script in Snowflake that gives you the exact same result as the statement you have provided, here is what you can do.
select day(convert_timezone('GMT','America/Los_Angeles',TO_TIMESTAMP_TZ('2020-04-14')::varchar));
Related
I am currently working on a project where is need to send existing tables with all their fields to an sql database (backend).
what i have so far is to generate an make-table query and then execute it, but i allways get the error....
"SELECT statement includes a reserved word or an argument name that is
misspelled or missing, or the punctuation is incorrect."
the generated string is SELECT * INTO (Provider=SQLOLEDB;SERVER=stserver;DATABASE=stdatabase;UID=userid;PWD=userpass).AAAANewTable FROM AAAANewTable WITH OWNERACCESS OPTION;
of cause the stdatabase and userid ect, are string variables :-)
Can anyone help me with the correct syntax? or give an example of what the correct syntax should look like?
Any help would be greately appreciated.
I have a 4 lines of SQL queries, where I have the following substring query:
SUBSTRING(T2.xxx,1,10) <= SUBSTRING(CONVERT(VARCHAR, T2.xxx, 111),1,10
I am using PySpark to create a HIVE table and push the data with the help of the query. There is no issue with the code as it is working for other SQL type queries. This is an instance where I am facing issues. Below is the error:
pyspark.sql.utils.AnalysisException: u"cannot recognize input near 'CHAR' ',' 'T2' in function specification
I have tried many online suggestions, but none of them work. I came across below link from the Cloudera website
https://www.cloudera.com/documentation/enterprise/release-notes/topics/cdh_rn_spark_ki.html
It says that:
Spark SQL does not respect size limit for the varchar type.
I am not sure if I have quoted the relevant statement here. Can anybody help me understand what I am going through here and how can I rectify the error?
I want a function to convert a varchar to hexadecimal in sql server. Please help me.
P.S. I will use unhex() in Hive to try to get the original value back. This is because my data contains special characters and backslash and the HIVE external table does not recognise it
You can try to use CONVERT function:
SELECT CONVERT(VARBINARY(MAX), 'myText')
Output:
0x6D7954657874
you can use
select try_convert(varbinary,varcharcolumn)
You should use try_convert to avoid errors when the conversion fails.. Also, varbinary(n) is a better alternative to varbinary(max) as the latter would set the page size to 2GB, which might be excessive.
Hope this helps!
I am new to SQL Server so please accept my apologies if my question seems too easy. I tried finding a solution, but so far I couldn't see anything that I could use in my query.
I am trying to find length of the biggest columns in a table and I'm using the following query.
SELECT
SUM(DATALENGTH([INSDetails])) as [INSDetails]
FROM
dbo.Contractors
The table Contractors is slightly over 8GB and has over 30mln rows. INSDetails column is varchar(2048)
The query above works perfectly well for all the other columns of all the other tables in my database, but when I run it on Contractors table it returns an error
Msg 8115, Level 16, State 2, Line 26
Arithmetic overflow error converting expression to data type int.
I understand that this error message appears when you try to convert a value of a certain datatype to another datatype, but that value is too large for the second datatype.
Could you please help me to rewrite the query or suggest alternative approach to get the output?
I read that someone suggested using CAST AS big int to solve this issue, but I'm not sure how it can be incorporated in my query.
Any suggestions will be appreciated. Thank you in advance.
select sum(cast(datalength([INSDetails]) as bigint))
I am stuck with a regular expression in SQL server 2005+, i.e. I need a regular expression to validate a first name (which allows only alphabets,whitespaces and a .(dot)).
I tried with below query
SELECT PATINDEX('%[A-Z]%[a-z]%[.]%','John H. Wilson') as VALIDFIRSTNAME
But, this also fails in some cases. I'm unable to find a clear regular expression. Any assistance would be very much appreciated.
I have used patindex to recognise the given pattern. If the string doesn't match the pattern, then It should give 0 else it should give 1 or >1.
Thanks in advance.
You can't match mentioned condition with available patterns.
Try to follow this way.