syntax error using convert function - sql

I'm trying to convert a timestamp into yyyymm format, and have found that this should do the trick:
select convert(nvarchar(6),getnow(),112);
I try to run this just as a POC that it will return in the proper format, but I get the following error:
ERROR: 42601: syntax error at or near ","
It works fine when I take out the style argument, but obviously does not return the desired format. I have no idea what could be happening and any help would be greatly appreciated.
Thanks!

I don't know if Redshift allow to format like SQL Server does.
So I suggest you to try with datepart. Something like this:
SELECT CONVERT(NVARCHAR(6), DATE_PART(y, getnow()) || DATE_PART(mon, getnow()) )

In SQL Server, it's getdate()...
select convert(nvarchar(6),getdate(),112)

This is the equivalent in Redshift:
select to_char(sysdate,'YYYYMM')

Related

select globalmap using tDBinput with Talend give the error: Invalid character constant

I have to remove the accents from the person's name, but I cannot apply the function in Talend while it works in SQL oracle.
this query works in my tDBInput component :
"SELECT '"+((String)globalMap.get("copyOfSORTIE.NOM"))+"' as nom_nom_compl,
'"+((String)globalMap.get("copyOfSORTIE.ENTETE"))+"' entete
FROM DUAL"
However, when I want to add the convert function, it doesn't work
this query does not work :
"SELECT '"+((String)globalMap.get(CONVERT("copyOfSORTIE.NOM",'US7ASCII')))+"' as nom_nom_compl,
'"+((String)globalMap.get("copyOfSORTIE.ENTETE"))+"' entete
FROM DUAL"
In my talend :
I am getting this error
What is the syntax for it to work?
Thank you!
Two things there :
I don't know the CONVERT method, but I can see that you are applying it to the key of your globalMap variable , and not the value (as if you wanted to convert "myKey" and not "myValue" which is attached to the key). Are you sure this is what you want to achieve ? if not, the syntax should be something similar to "SELECT CONVERT('"+((String)globalMap.get("copyOfSORTIE.NOM"))+"','US7ASCII') "
A useful java method implemented in talend is TalendString.removeAccents("") that you can apply directly on your talend variable, thus not using a SQL method.

Convert Integer to Date in Snowflake using Error Handling

I have a requirement where integer value should be converted to date type in Snowflake.Initially I used following query to get the desired result:
SELECT TO_DATE(TO_varchar(19000000+1200034),'YYYYMMDD')
2019-07-09
Now when I used same query for the input - "20200034", I am getting following error:
select TO_DATE(TO_varchar(19000000+1200034),'YYYYMMDD')
Can't parse '20200034' as date with format 'YYYYMMDD'
"20200034" is actually coming from one of the columns in snowflake table. To resolve this issue I tried using "TRY_TO_DATE" function, but output of "TRY_TO_DATE" function is giving incorrect result. Please find details below:
select TRY_TO_DATE(TO_varchar(19000000+1200034))
1970-08-22
As per Snowflake documentation, error handling function does not support optional format argument supported by TO_DATE , DATE.
https://docs.snowflake.com/en/sql-reference/functions/try_to_date.html
You can set the DATE_INPUT_FORMAT for the session before calling the TRY_TO_DATE function.
I suggest you contact Snowflake support and ask them to enable try_to_date with format string - it's available but needs to be enabled manually.
However you have to be aware that TRY_TO_DATE on '20200034' will be resolved to NULL.

Microsoft SQL error in string for wrong syntax

First time posting on here.
Please can someone help me with this very simple error that I cannot seem to fix.
if #DivResult > 0 and #IfMenu = ('A','F')
There is a syntax error near the comma
This is not valid tsql syntax: and #IfMenu = ('A','F')
The correct would be: and #IfMenu in ('A','F')

Ms Access Syntax issues

My problem is that I would like to realize this, but it throws syntax error.
WorkDayUltimate: Format(DateAdd("mm/dd/yy","h",-6,[Outgoing Date])
Thanks for your help in advance.
You must first add to date, then format:
WorkDayUltimate: Format(DateAdd("h",-6,[Outgoing Date]),"mm/dd/yy")

Access SQL for sorting by date with TempVars

im trying to make a query from the use of TempVars
im Using SQL to run the query but every time i try, it return Invalid date value
this is the line that will not work
this returns error
WHERE ((([Table].[Issue Date])>=#[TempVars]![tmpDateFrom]# And ([Table].[Issue Date])>=#[TempVars]![tmpDateTo]#));
this returns fine
WHERE ((([Table].[Issue Date])>=#10/12/12# And ([Table].[Issue Date])>=#11/12/12#));
I have checked the TempVars [tmpDateFrom] and [tmpDateTo] and they out put the date value i need.
Please help
Thank you all or the help.
due to the requirement of the database #Nicarus had the right answer this is the solution for those still wondering.
WHERE ((([Table].[Issue Date])>=[TempVars]![tmpDateFrom] And ([Table].[Issue Date])>=[TempVars]![tmpDateTo]));