How to create Dynamic SQL in Pentaho Report Designer? - sql

I have a requirement where columns of the SQL will be generated based some selection, these columns are coming from Metric dimension but there is no metric ID present in Fact table.
SQL would be something like below:
SELECT Location_Nbr, Day_Nbr, (Column_List- Coming from some other query)
FROM (Table_Name - Coming from same query which is providing Columns to be selected)
I tried creating the SQL query but I get an error saying there is not a business relation between these tables. Is there any other way to achieve this?

To use Dynamic SQL in Pentaho Report Designer, you need to use
custom jdbc connection in data source
then in master report query name, select message format
type your dynamic query in message Pattern
select
$(dynamic_data) as 'data' from table_name;

Related

Get query used to create a table

We use snowflake at work to store data, and for one of the tables, I dont have the SQL query used to create the table. Is there a way to see the query used to make that table?
I tried using the following
get_ddl('table', 'db.table', true)
but this gives me an output like-
This doesnt give me any information about the sql query that was used. How do I get that in snowflake?
If get_ddl() is not enough you may use INFORMATION_SCHEMA.
To get more information you have 2 options:
Use the QUERY_HISTORY() table functions: https://docs.snowflake.com/en/sql-reference/functions/query_history.html
Use the QUERY_HISTORY() view: https://docs.snowflake.com/en/sql-reference/account-usage/query_history.html
If you use the funtions/view above and filter all the records by QUERY_TEXT, maybe you get more information about the exact SQL that was used to create your table.

SQL to add only new data

I'm using Pentaho Data Integration, and in it, I make a selection in database X, where I get some information with filters, then I need to update this information in database Y. However, I need to ignore the data already recorded and just add the new data, as can i do this with a sql?
you could use a merge statment for that
if your fields names are same in tables you can use this query:
insert into Y.dbo.Y_1(fieldName)
select fieldName from X.dbo.X_1

BigQuery create Table differences between standard and legacy sql

I have a few questions around the create table syntax in standard and legacy sql
The new BigQueryUI doesn't show standard sql types and shows only legacy types. I understand they are mapped one to one with the legacy types but the examples in creating partitioned tables shows options which are not available in the UI
If I create a table using the JSON field schema can I still use the standard sql?
The BigQueryUI shows only partitioning the table by Ingestion time, but I want to create a table with date column and I don't see an option for it. If I have to create the DDL manually, I did not see the examples on how to use JSON field schema to construct a create table statement.
The new BigQueryUI doesn't show standard sql types
BigQuery standardSQL and LegacySQL are 2 options to write SQL syntax (See this link for more detail) and have nothing to do with the column Types in BigQuery, Details on table types can be found in this link, I also find this Link helpful
If I create a table using the JSON field schema can I still use the standard sql?
To create a table using JSON you need to run bq command line, If you need help how to write this syntax let us know
but I want to create a table with date column and I don't see an option for it
You can use this standardSQL syntax to do this:
#standardSQL
CREATE OR REPLACE TABLE `project.dataset.tableId`
PARTITION BY myDate
CLUSTER BY cluster_col AS
SELECT * from sourceTable
Note: myDate column is a column in the source table

Writing SQL in Informatica Data Quality Analyst

I am new to Informatica Data Quality Analyst (Version 9.5.1 HotFix3) and I am having trouble in generating a basic SQL statement.
The SQL statement is being written against a mapping specification of a table that was originally imported as a flat file. The statement looks like:
Select ColumnA, ColumnB FROM Table1
WHERE Table1.ColumnA = 'S'
The SELECT .... FROM portion of the statement works fine but I encounter errors when I throw in the WHERE clause. I think my statement looks like standard SQL so I'm not sure why this will not work. Does Informatica Analyst accept SQL written only in a specific form? Are the inverted commas causing problems?
the query must work which you are trying to execute. If its not fetching the results, you need to do the following steps:
1) Load the data from source flat file to any database(oracle). You can directly import the data from flat file to table via sql developer.
2) Execute the query with the filter condition. If it doesnt fetch any rows, your query in idq is fetching correct results. If not, there is something missing in your idq code.

How to Check Teradata Table Definitions

In my Teradata SQL Assistant Client, I can right-click a table and select Show Definition, this will display the column types and how they are defined.
Is there a query that can be run to give me the same output? More specifically I'm trying to display the definition of a view that is created from certain tables that I do not have SELECT or VIEW DEFINITION access to.
SHOW TABLE {Database_Name}.{Table_Name};
SHOW VIEW {Database_Name}.{View_Name};