SQL (DB2) Creating table by selecting from other table - sql

I´ve read several discussions and websites about creating a SQL query to create a table by selecting data from other table, but none of them solved my issue. I don´t know what else to do.
I am working on a SQL script to run a sequence of selects and creates do resume some data. I´ve been using this SQL queries on a SaS server using DB2 data. Now I need to migrate to Dbeaver to using other sources.
I just want to create a table by selecting some columns and data from other table, for this simple example :
"CREATE TABLE DB2XXXX.PaidResume AS
(SELECT HistoricalPaid.AccountNumber AS CONTA
FROM DB2XXX.HistPaid HistoricalPaid
WHERE HistoricalPaid.AccountNumber = 'XXXXX');
All I got it this error
Error occurred during SQL query execution
SQL Error [42601]: ILLEGAL SYMBOL "<END-OF-STATEMENT>". SOME SYMBOLS THAT MIGHT BE LEGAL ARE:. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.19.26
If I just exclude the "CREATE TABLE DB2XXXX.PaidResume AS" and run the select only, it works.

You must include WITH DATA or WITH NO DATA at the end of the SQL statement. For example:
create table u as (select a from t) with data;
See example at db<>fiddle.

Related

executing sql query in UiPath to extract data from snowflake

I am using execute query activity in Uipath studio and writing the sql query like this
"select * from SNOWFLAKE_SAMPLE_DATA where value=CALL_CENTER"
to extract the table values from snowflake.
where "SNOWFLAKE_SAMPLE_DATA" is the database and "CALL_CENTER" is the table which is present in the said database.
After I execute the query in uipath it gives the following error:
Execute Query: ERROR [42S02] SQL compilation error: Object
'SNOWFLAKE_SAMPLE_DATA' does not exist or not authorized.
Any help in this regard will be highly appreciated.
Thank You
You will need to update your SQL query.
The correct syntax is SELECT * FROM [database.table];
If you want to pull everything from the table, you will need to enter the line below (in double quotes) in the Sql property of the Execute Query activity:
SELECT * FROM SNOWFLAKE_SAMPLE_DATA.CALL_CENTER;
Lastly, the output will need to go to a data table.

SQL Oracle developer with hive connection - using of temp tables

We are using hive connection with oracle SQL developer tool.
Is it possible to use temporary tables while querying external tables through sql developer tool?
Tried this , But doesn't work
CREATE PRIVATE TEMPORARY TABLE my_temp_table (
id NUMBER,
description VARCHAR2(20)
);
Error :
SQL Error: [Cloudera]HiveJDBCDriver ERROR processing query/statement. Error Code: 40000, SQL state: TStatus(statusCode:ERROR_STATUS, infoMessages:[*org.apache.hive.service.cli.HiveSQLException:Error while compiling statement: FAILED: ParseException line 1:7 cannot recognize input near 'CREATE' 'PRIVATE' 'TEMPORARY' in ddl statement:28:27, org.apache.hive.service.cli.operation.Operation:toSQLException:Operation.java:335,
You can't use an Oracle Database syntax against a hadoop/HIVE target, even with the Oracle Big Data Connector.
Here are the CREATE TABLE clauses available to you
https://docs.oracle.com/en/bigdata/big-data-sql/4.0/bdsug/bigsqlref.html#GUID-066A4568-9F95-4305-A1A5-7BC3E5DF35AF
Here are examples for querying your external table
https://docs.oracle.com/en/bigdata/big-data-sql/4.0/bdsug/bigsql.html#GUID-0628EC5B-E013-40DF-A025-908019F4E681

Listagg Redshift DDL

I am trying to retrieve the DDL for a table in Redshift. I found this view where I can easily select the definition for any table. However I need this information in one line, and I know that there is this Listagg function, but if I try to do this:
select listagg(ddl, ' ')
from admin.v_generate_tbl_ddl
where schemaname = 'schema'
and tablename = 'orders'
It's giving me this error:
Query execution failed
Reason: SQL Error [XX000]: ERROR: One or more of the used functions
must be applied on at least one user created tables. Examples of user
table only functions are LISTAGG, MEDIAN, PERCENTILE_CONT, etc
Can You please help me on how can I achieve this?
listagg function is a compute-node only function.
But the query you run to get the table ddl runs only on leader because it only specifies pg_* tables.
According to AWS documentation
A query that references only catalog tables (tables with a PG prefix, such as PG_TABLE_DEF) or that does not reference any tables, runs exclusively on the leader node.
If a query that uses a compute-node function doesn't reference a user-defined table or Amazon Redshift system table returns the following error.
[Amazon] (500310) Invalid operation: One or more of the used functions must be applied on at least one user created table.
https://docs.aws.amazon.com/redshift/latest/dg/c_SQL_functions_compute_node_only.html
To sum up, since your query does not reference any user created table, you can not use listagg

I get this error "Optimistic concurrency control error" when I want edit a SQL Server view

I have two tables table_1 and Table_2; I created this view in SQL Server:
SELECT dbo.Table_1.ID, dbo.Table_1.Title, dbo.Table_2.Descc
FROM dbo.Table_1
LEFT OUTER JOIN dbo.Table_2 ON dbo.Table_1.ID = dbo.Table_2.ID
But when I want to enter data into Descc column, I get an error
Optimistic concurrency control error
This issue occurs if the following conditions are true:
The table contains one or more columns of the text or ntext data type.
The value of one of these columns contains the following characters:
Percent sign (%)
Underscore (_)
Left bracket ([)
The table does not contain a primary key.
Note This issue also occurs when you try to use Table Designer in Microsoft Visual Studio 2005 to update a table that is in a SQL Server 2005 database.
Workaround
To work around this issue, create a new query window in SQL Server Management Studio. Then, run a SQL UPDATE statement to update the row in the table.
Note If you receive the first error message that is mentioned in the "Symptoms" section, you can click Yes to update the row.
microsoft link

MS Access database: Select statement error

I am trying following query in MS Access 2010 database:
Query:
SELECT ID, Title, Priority, Workflow_Instance_Step_ID:ID
FROM Task
Error:
Error Source: Microsoft Office Access Database Engine
Error Message: Syntax error (missing operator) in query expression 'Workflow_Instance_Step_ID:ID'
I know that field "Workflow_Instance_Step_ID:ID" is giving error as it has ':' operator, but I cant change it as it it coming from share point list.
I have tried '[Workflow_Instance_Step_ID:ID]' but still its giving an error.
Please give me your suggestion on the same.
I am unable to recreate your issue, at least with a native Access table in Access 2010. I created a table named [baz] with a single text field named [foo:bar]
foo:bar
-------
this
is
a
test
and the query
SELECT [foo:bar] FROM baz;
works fine, so a field name containing a colon character does not seem to cause problems for Access SQL as such.
An ODBC linked table to a SQL Server table with the same structure does not cause problems either.
In both cases the queries were run from within Access 2010 itself.
So we might be in diagnosis mode, so lets try
SELECT * FROM Task
and then look at the FieldNames that come back.