SQL that does run on SQL assistant does not run in Teradata Studio Express. I have narrowed it down to the date syntax within the SELECT statement. What is the proper syntax (in the SELECT Statement) to return the date entered by the user in the result set. I have changed the prompt syntax to '?\FirstDayOfWeek' within the conditions & that does function properly as a pop up for the user, however it does not allow the query to run when used in the select statement.
Thank you!
Related
Is there a fundamental difference in DBeaver between executing a script and executing the same statements as "Execute Statement" instead?
With the following PostgreSQL script
SELECT TXID_CURRENT();
SELECT TXID_CURRENT();
If I execute both as part of a single "Statement", it looks like they are executed within the same transaction
While if I execute the "script", they seem to be fired individually (not inside a common transaction)
Is this a feature of DBeaver or PostgreSQL?
From the manual:
-> Execute SQL Statement. This executes the SQL query under cursor or selected text and fills the results pane with the query results.
-> Execute SQL Script on the main menu or in the main toolbar. This executes all queries in the current editor (or selected queries) as a script. DBeaver parses queries one by one using a statement delimiter (“;” by default) and executes them consecutively.
When I'm sketching out SQL statements I have a file of all the queries I have used to analyse my live data. Each time I write a new statement or group of statements at the end of the fileI select them and click 'execute' to see the results. I'm paranoid that I may forget the selection stage and accidentally run all the queries sequentially in the entire file and so I head the file with the line
USE FakeDatabase
so that the queries will fail as they will be run against a non-existing database. But no, instead I get the error
USE statement is not supported to switch between databases
(N.B. I am using SQL Server Management Studio v17.0 RC1 against a v12 Azure SQL Server database.)
What tSQL statement can I use that will prevent further execution of tSQL statements in a file?
use is not supported in AZURE...you can try below ,but there can be many options depending on your use case
Replace use Database with below statement
if db_name() <>'Fakedatabase'
return;
You could, instead, put something like this in each script:
IF ##SERVERNAME <> 'Not-Really-My-Server'
BEGIN
raiserror('Database Name Not Set', 20, -1) with log
END
-- Rest of my query...
For example, I'd like to run:
REGEXP_REPLACE("What's My Name?", "[^a-z0-9_\-]", "-");
and simply see what it returns, instead of doing a search against a DB Table. I tried to run it in the CLI and got
ERROR: syntax error at or near "REGEXP_REPLACE"
LINE 1: REGEXP_REPLACE("What's My Name?", "[^a-z0-9_\-]", "-")
(I'm trying to be generic- I'd like to be able to use this for other PSQL Aggregate Functions as well.)
Remember, this is SQL, so every output you get is a relation. Hence to calculate the result of a function, you need to run SELECT to retrieve the function's value.
Unfortunately, in many DBs, SELECT requires a table. In Oracle land, there's dual to work around this problem:
SELECT REGEXP_REPLACE('What''s My Name?', '[^a-z0-9_\-]', '-') FROM dual;
PostgreSQL, however, allows you to execute a SELECT query without having to specify a table:
SELECT REGEXP_REPLACE('What''s My Name?', '[^a-z0-9_\-]', '-');
Note that the string quote in SQL is ', not ". PostgreSQL uses double quotes to quote identifiers.
Side note: Not every function is an aggregate. An aggregate is a function that combines multiple values into a single output value. REGEXP_REPLACE() is just a normal string function.
Is there a way to run a single PSQL Aggregate Function without hitting a database table?
Yes, in PostgreSQL you can write a SELECT statement without a FROM part at all.
I am a first time DB2 user, have trouble in executing "list tables;" in IBM Data Studio.
I can run "select" commands (end with semicolon) and "update commands" but "list tables;" (both with and without semicolon) gives following error:
An unexpected token "END-OF-STATEMENT" was found following "LIST TABLES".
Expected tokens may include: "JOIN <joined_table>".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.14.113
Update: Alternatively, the following command works:
select tabname from syscat.tables where tabschema = 'whatever-schema-name';
BTW, is it possible to change the default query result window from "Status" to "Result1". It is in "Status" window by default and every time I have to click "Result1" tab to see the query result.
I am not sure about what I am going to say, but Data Studio is only for SQL commands. List table command is not a DDL, DML nor DCL, and for this reason, you cannot execute that command from the SQL editor in Data Studio. Those commands are for the CLP.
use list all the tables in the DB as given below
db2 list tables for all
use list all the tables in the Schema as given below
db2 list tables for schema scheme_Name
I have written a DB2 query to do the following:
Create a temp table
Select from a monster query / insert into the temp table
Select from the temp table / delete from old table
Select from the temp table / insert into a different table
In MSSQL, I am allowed to run the commands one after another as one long query. Failing that, I can delimit them with 'GO' commands. When I attempt this in DB2, I get the error:
DB2CLI.DLL: ERROR [42601] [IBM][CLI Driver][DB2] SQL0199N The use of the reserved
word "GO" following "" is not valid. Expected tokens may include: "".
SQLSTATE=42601
What can I use to delimit these instructions without the temp table going out of scope?
GO is something that is used in MSSQL Studio, I have my own app for running upates into live and use "GO" to break the statements apart.
Does DB2 support the semi-colon (;)? This is a standard delimiter in many SQL implementations.
have you tried using just a semi-colon instead of "GO"?
This link suggests that the semi-colon should work for DB2 - http://www.scribd.com/doc/16640/IBM-DB2
I would try wrapping what you are looking to do in BEGIN and END to set the scope.
GO is not a SQL command, it's not even a TSQL command. It is an instruction for the parser. I don't know DB2, but I would imagine that GO is not neccessary.
From Devx.com Tips
Although GO is not a T-SQL statement, it is often used in T-SQL code and unless you know what it is it can be a mystery. So what is its purpose? Well, it causes all statements from the beginning of the script or the last GO statement (whichever is closer) to be compiled into one execution plan and sent to the server independent of any other batches.