Adding current date in create script for Snowflake - snowflake-cloud-data-platform

I have a requirement where I have to create tables with the date/datetime in the table name when they were created dynamically.Wondering if this option is possible in Snowflake?
Eg:
I would need somethinglike this.
CREATE TABLE someNewTable_YYYYMMDD
Thank you for your responses;
Best,
AB

You can achieve this using SQL variables and the IDENTIFIER keyword.
Here's an example that adds the current date into the table-name:
SET table_name=(SELECT 'someNewTable_' || TO_VARCHAR(CURRENT_DATE(), 'YYYYMMDD'));
CREATE TABLE IDENTIFIER($table_name) (col STRING);
For more complicated tasks where using IDENTIFIER keyword is inadequate, you can also use stored procedures as shown in this answer.

Related

Querying Column Name as Variable Using Tableau Custom SQL

I am building a lookup tool that will take Column Name and Table Name as inputs from Tableau as Parameters, and plug those in to Tableau Custom SQL as Parameter values, but I cannot find a way to make the Column Name dynamic in the select query.
Here is the idea:
Select ParameterColumnName
FROM TABLE(ParameterTableName)
I have investigated Snowflake's "IDENTIFIER" commands, but those seem to work only in the FROM clause of the query. I have tested with a static column name and dynamic table name and that works fine.
I have also explored setting variables with the parameter column name values, but I cannot seem to use "SET" in Tableau Custom SQL--it does not recognize SET. Appreciate any pointers.
Update: This post appears to address why I cannot set variables from Custom SQL, but if that's not it, let me know!

Snowflake External Table DDL

I am aware that we will not be able to get the DDL for the external table using GET_DDL function in snowflake. Is there any workaround to get the DDL( Create Statement) for the external table in snowflake?
You can get pretty close using the DESC EXTERNAL TABLE command and then leveraging the expression column to then build at least some of the DDL, but there is no workaround to get the direct DDL statement that was used. In addition, the SHOW EXTERNAL TABLE command will provide the external files being leveraged.

How to map table in ODI 11 if this table not exist yet

I have a situation here that I do not know what to do.
I have a table in the source system of my ETL that is created by the system at the end of the month. The table name is like Table_MM_YYYY, where MM_YYYY is the month and year.
I need to map this table and use it in an ODI interface.
Suggestions?
I guess this is possible by using variables in the ODI. That is, if you do not change the table structure then in the Source table substitute the name of the variable, and already in the variable will be the name of the table. In the variable, put the name of the table created at the end of the month according to the capacity of the request or procedure. I think that gave some impetus. Watch this link it like what you need with file only watch this link

SSIS 2008 R2 - Can I set a variable to the name of the current scope?

This seems ridiculously easy, but I can't find it anywhere...
I have a VERY simple sequence container with two tasks: Truncate a SQL table, and repopulate it from production. But this container will be repeated for about 50 tables. The container's name (entered manually) = the name of both the source and destination tables.
I have two variables:
"TableName" is entered manually.
"DelTable" is an expression that uses #[User::TableName] to generate a simple SQL statement.
I'm super-lazy and would like to use an expression to set "TableName" = the name of the current scope so I only have to enter it once.
Ideas???
THANK YOU!
if you are truncating all tables in a DB and replacing with exactly the same structure, how about this approach:
Execute SQL:
select table_name
from INFORMATION_SCHEMA.TABLES --Add a where to limit the tables to the ones you want
Save results to an object variable called TABLES
Add a for each loop:
Loop through ADO Object setting value to a string variable called table
Add Execute SQL to FE LOOP: truncate table ? and map parameter.
Add a 2nd Execute SQL statement:
INSERT INTO SERVER.DB.SCHEMA.?
select * from ?
Again map the parameters.
If you are having trouble mapping parameters set up variables and use them to create the SQL statements to run.
#TomPhillips is correct, I cannot unfortunately comment or make that answer useful. hence commenting here.
There's no easy quick fix to use a loop/automate unless all the 50 tables are same structure which is rare by any stretch of imagination.
BIML is the way to go if you are lazy :)
SSIS is not dynamic. Data Flows require fixed input and output at compile time, not runtime. You cannot simply change the table name and have it work.
If you have a list of 50 tables to do the same function on, you can use BIML to dynamically generate the SSIS package(s). But the DF itself cannot be dynamic.

SQL - How to check if altering a table will break any stored procedures

Is there a nice way before I alter a table (e.g. remove a column), to see if that this will break any stored procedures?
I am trying to do this in MS SQL Server
Use the query here to search all stored procedures for the table and column name. You will probably still want to look at the code for each one you find to verify that it will or won't break.
you can use the following query to search for the table name in any stored procedures:
SELECT name
FROM sys.procedures
WHERE Object_definition(object_id) LIKE '%Your_Table_Name%'
I suggest you:
Make sure you have a separate environment (DEV)
Use the sample code from here to create a proc that confirms all objects in the database can be recompiled
How to Check all stored procedure is ok in sql server?
Use it - I can guarantee you will already have failing objects before you remove your column
Remove your column and use it again to see if more things broke
The more mature approach to this is to put your database into a database project and build that. But you can't do this until your database is valid.

Resources