05-15-2020 06:39 AM
Hi, I have few tables on SQL server like
abc_2020
abc_2019
abc_2018
I want to query the the table that has suffix as current year. I have specified the value
in the settings > table name-- ‘abc_’+ Date.now().getFullYear()
it’s throwing error.
Failure: Failed to retrieve metadata for table: “‘abc_’+Date”.“now()”.“getFullYear()”, Reason: Database ‘now()’ does not exist. Make sure that the name is entered correctly., Resolution: Database ‘now()’ does not exist. Make sure that the name is entered correctly.
When I hard-code the table name as abc_2020 it is working.
Can someone help me with this ?
06-02-2020 09:07 PM
instead of using the getFullYear which by the way the output in an integer type which I think causing the sql select snap to haywire 🙂 you can use concat
e.g.
‘abc_’.concat(Date.now().toLocaleDateString({‘format’:‘yyyy’}))
or if you want to stick with the getFullYear() try to cast it as string
‘abc_’ + Date.now().getFullYear().toString()
06-03-2020 01:39 AM
@alchemiz It didn’t work
06-03-2020 07:14 AM
I saw this write up from a Postgesql update snap, I wonder if this applies to all database type snaps ?
Do you mind putting a pipeline parameter and test it? If this can be allowed from the pipeline parameter then you can use an expression library and put the function there
sample of expression file content
{
‘getDynamicTableName’ : (table_prefix = “abc_”) => table_prefix.concat(Date.now().getFullYear().toString())
}
then set the expression file in the pipeline and invoke the method in the SQL select snap under table name
e.g lib.extender.getDynamicTableName()
The values can be passed using the pipeline parameters but not the upstream parameter