Dynamically create table name with current month HIVE SQL - hive

I am trying to setup an automated script that finishes by creating a new table with that month's name abbrev appended to the table name (e.g. tablename_Jun2022)
I have the following variables with the month/date below:
set hivevar:curr_date=trunc(to_date(from_unixtime(unix_timestamp())),'MM');
set hivevar:curr_month=date_format(${curr_date},'MMM');
However, I'm unable to use the curr_month variable in a table name:
create table tablename_${curr_month} as...
since the hivevar isn't storing the end result.
Anyone done this before/know a workaround? Thanks.

Related

Is it possible for a HIVE table to point to a dynamic Location based on a variable like CURRENT_DATE?

I want to be able to define (or create) a HIVE table with location having a variable. As the variable value changes, query on the HIVE table should read the files under the new location based on the variable value. Specifically, I want to use CURRENT_DATE to let the HIVE table fetch from a different folder each day.
Is this possible?
Location is a part of table/partition DDL. You can use
ALTER TABLE/PARTITION SET LOCATION
or add partition with new location:
ALTER TABLE ADD PARTITION
and pass partition specification to the query as a parameter

Declare variable in template table

I am writing an ETL to extract data from HANA table and load into SQL Server in BODS.
My job is to create a new table on SQL Server every time I run my job with name as date of that day. I know we can do that for flat files by using global variable but not sure how we can declare similar variable in template table to get desired results?
Why you want to use template tables. You can do the same as below:
Load the data in a standard staging table using BODS
Using DS scripting mechanism generate a query to create a table
Execute the query using SQL transform
Generate another query to copy data from staging table to the table created above
Several other ways also like you can write a DB procedure to create a table with the desired name and copy over the data from stage to that table. This procedure you can call from DS.
Hope this helps.
Cheers.
Shaz

How to insert into netezza table from SSIS with sequence value

I am trying to do a basic dataflow task in SSIS2012 where the destination is a Netezza table. I have a column that I named "Transaction_ID" that I am planning to use as a primary key and I have a sequence ready to populate it (Seq_Transaction_ID). However, I am not sure how exactly to assign the sequence.
For instance I tried making the table and assigning the column to a default of the next value for the sequence and got an error "you can only use a next value function within a target list". I'm also not sure how I would get the sequence into SSIS either.
Any ideas?
Thank you,

loop row by row from an excel file map to variable

I have 4 columns in an excel file. I need to assign values from each row to the corresponding 4 variables so they can be replaced lated in a query i am doing on a server.
My question is: How to do that?
So far i tried doing an SQL task in which i create a table with 4 columns (having the same names as those in my excel file) and a task to transfer the content of the excel to a recordset destination which stores the results into a variable. I also created a foreach loop in which i am having my tasks. What am I missing, how can I do this?
Thanks
EDIT
please find below a screenshot from my project. This is the overview.
In "Execute SQL Task" there is a connection to excel and has the following statement
CREATE TABLE tempVariableMapping
(
AsofDate varchar(20),
Assump_Set varchar(20),
MarketName varchar(20),
Portname varchar(20)
);
Then in the transfer task (in the recordset destination), i'm assigning the variable name to User::RecordSetOutput which is a global variable of type object.
In foreach loop i'm using a foreach ado enumerator and pointing to that User::RecordSetOutput variable find below the variable mapping
Those 4 variables in variable mapping are those in which i want to pass the values from each row of the excel file.
The sequence container and create temp table are just dummy. Haven't figured out the correct way. Everything below that, works.
Sorry for the missunderstanding, hope this is enough to get the picture.
Thank you for your time and help

vb.net query for creating table

I have Access as my back end. Student is the database name and its path is c:\Project\student.mdb
And am having few tables in it. When i click a command button in vb.net a new table must be created in the path mentioned. And it should have the fields I declare.
What s the query I need to use ? Is it possible to do like that ?
Yes, it's possible, you can check out the syntax for the create table command.
However, I have to say that creating tables dynamically suggests a bad database design. The database layout should normally remain the same whatever data you put in the database.
If you create tables dynamically, that means that you have data in the table names, but data should go inside the tables, not in table names (or even field names).
Yes it's possible . Just pass the create table command as query and the table name as variable , which you want to add dynamically. for reference of create table command
Create table command