Why am I getting an error near semi colon (:)? - tsql

I have no idea but this is throwing an error i think it is on line "set #al = 2020". I have read the documentation and not seeming to translate over.
begin
declare #al int;
set #al = 2020;
exec dbo.get_egus_trdg_desk_rpt_no_clrg_broker(#al int);
end
Error message:
SQL Error [102] [42000]: Incorrect syntax near ';'.

You do not need to use ';' after every line of code. I can successfully generate the following script in SQL Server 2019.
Sample Output

Related

postgresql 11 ERROR: syntax error at or near "`"

I installed Mimic3 database in Pg11, and try to query using the code from here: https://mimic.physionet.org/tutorials/intro-to-mimic-iii-bq/ solution to step 1.
SELECT ie.subject_id, ie.hadm_id, ie.icustay_id,
ie.intime, ie.outtime
FROM `physionet-data.mimiciii_clinical.icustays` ie;
but I got the error.
ERROR: syntax error at or near "`"
LINE 3: FROM `physionet-data.mimiciii_clinical.icustays` ie
^
, Time: 0.004000s
And if I deleted those two backticks, I got the warning.
ERROR: syntax error at or near "-"
LINE 3: FROM physionet-data.mimiciii_clinical.icustays ie
^
, Time: 0.002000s
And if I explaced ` with ", it showed the error that:
ERROR: relation "physionet-data.mimiciii_clinical.icustays" does not exist
LINE 3: FROM "physionet-data.mimiciii_clinical.icustays" ie
^
, Time: 0.002000s
Hope somebody can tell me what was wrong. Thank you!
Postgres doesn't use backticks to quote table names, it uses double quotes, and dots aren't allowed in names without quoting, so you probably want this:
SELECT ie.subject_id, ie.hadm_id, ie.icustay_id,
ie.intime, ie.outtime
FROM "physionet-data.mimiciii_clinical.icustays" ie;

Select query in FOR loop does not works in Netezza

I am trying to run a simple plsql in Netezza, to run a loop on a result set of select query,
here is the below code I am trying to run
CREATE OR REPLACE PROCEDURE UPDATE_SUSPECT_GROUP_ID()
RETURNS CHARACTER VARYING(ANY) EXECUTE AS CALLER
LANGUAGE NZPLSQL AS
BEGIN_PROC
DECLARE
VAL BIGINT := 100000000000000;
BEGIN
RAISE NOTICE 'lets start';
FOR r IN
select
suspect_id as suspect_id
from apollo_customer_analysis.ASHKUMAR.REFINED_SUSPECT
LOOP
RAISE NOTICE 'val: %',r.suspect_id;
END LOOP;
END;
END_PROC;
EXECUTE UPDATE_SUSPECT_GROUP_ID();
When try to run the code, I get the below error
ERROR [01000] NOTICE: plpgsql: ERROR during compile of UPDATE_SUSPECT_GROUP_ID near line 15
ERROR [01000] NOTICE: line 1 at execute statement
ERROR [HY000] ERROR: syntax error, unexpected ';', expecting LOOP at or near ";"
Can someone help me how this error could be resolved?

Postgres: if-else condition depending on prompt, in .sql file called via \i

With Postgres 10.10, here is what I am trying to accomplish. I want to have a test.sql script file (executed by \i /path/test.sql) whose code execution depends on what the user inputs after an initial prompt.
For instance, with code below I would like some text to be echoed and a table to be created, but the echoed text and the table name should depend on the text passed by the user as input to a prompt:
\prompt 'What is your favourite color?' answer
IF ('blue' = :answer) THEN
\echo 'It is blue! :) '
CREATE TABLE blue;
ELSE
\echo 'It is something else. :( '
CREATE TABLE :answer;
END IF;
However, a few errors prevent that from working:
myuser=# \i /home/myuser/test.sql
What is your favourite color?red
It is blue! :)
psql:/home/myuser/test.sql:4: ERROR: syntax error at or near "IF"
LINE 1: IF ('blue' = red) THEN
^
It is something else. :(
psql:/home/myuser/test.sql:7: ERROR: syntax error at or near "ELSE"
LINE 1: ELSE
^
psql:/home/myuser/test.sql:8: ERROR: syntax error at or near "IF"
LINE 1: END IF;
^
myuser=#
Notice that this is not the same as asked in https://dba.stackexchange.com/questions/207666/how-do-i-use-the-input-from-a-prompt-in-a-conditional-if. Also, I tried adapting it to follow the answer in Postgres syntax error at or near "IF", but then I just get more errors, starting with "syntax error at or near 'DO'".
Is there a way for me to accomplish this task? That is, every time an user executes the test.sql file with \i, the user is prompted and the execution of the code within the file branches depending on the text that the user inputed via prompt?
Something like this:
SELECT :'answer' = 'blue' AS isblue \gset
\if :isblue
...
\endif

Is there a way to have Postgres tell you what a syntax error was in addition to what it is at/near?

I've tried setting 'log_min_error_statement' equal to debug5 in postgresql.conf but I'm still getting the standard "PostgreSQL said: syntax error at or near "AS"" error message in both the console and the postgresql log.
If PostgreSQL knew what the error was it'd tell you, at least in most cases.
If it just says "Syntax error at or near ..." it doesn't know what you meant, and can't guess what's wrong. It's a parse error. It could offer a (very long) list of suggestions, but that'd make error messages absurdly verbose, like:
postgres=# SELECT AS fred ORDER BY 1;
ERROR: syntax error at or near "AS"
LINE 1: SELECT AS fred ORDER BY 1;
Yup, that's a syntax error, because it doesn't make sense on any level. What's wrong with it? How do you succinctly describe that? How does a parser even tell what's wrong?
postgres=# SELECT AS fred ORDER BY 1;
ERROR: syntax error at or near "AS"
LINE 1: SELECT AS fred ORDER BY 1;
HINT: typo?
HINT: Did you use a reserved keyword as an identifier without "quoting" it? Like "AS"?
HINT: Did you leave out the value before the AS keyword?
HINT: ... endless possibilities ...
Occasionally a parser can guess something you might've done wrong. PostgreSQL's parser tries to tell you when it can, e.g.
psql -c "SELECT 'openquote";
ERROR: unterminated quoted string at or near "'openquote"
LINE 1: SELECT 'openquote

DDL Create Trigger script fails

A DDL script to create a trigger (source below) fails with 2 errors:
Statement failed, SQLSTATE = 42000
Dynamic SQL Error
-SQL error code = -104
-Unexpected end of command - line 3, column 44
After line 0 in file C:\CRMDemo\Database\DDL\Trigger_Orders.sql
Statement failed, SQLSTATE = 42000
Dynamic SQL Error
-SQL error code = -104
-Token unknown - line 1, column 1
-end
At line 14 in file C:\CRMDemo\Database\DDL\Trigger_Orders.sql
(line 3, column 44 looks like it may be the closing parthesis).
I can't find any information about errors 42000 or -104.
The trigger is designed to assign a record number from a generator, which does exist. This trigger works properly in Interbase from the same script.
The only thing I can think of is that the column size, Integer, is incorrect for the value returned. But the documentation says the value may be truncated but should work for the expected value (1).
CREATE TRIGGER ORDERS_GENERATE_KEY FOR ORDERS ACTIVE BEFORE INSERT POSITION 95 AS
begin
NEW.ORDER_NR = GEN_ID(NEW_ORDER_NUMBER, 1);
end;
Firebird is ver 2.5.2, just downloaded. Windows 7. Database should be 32bit.
If you run your statement using isql utility take sure that SET TERM operators are used:
SET TERM ^ ;
CREATE TRIGGER ORDERS_GENERATE_KEY FOR ORDERS
ACTIVE
BEFORE INSERT
POSITION 95
AS
begin
NEW.ORDER_NR = GEN_ID(NEW_ORDER_NUMBER, 1);
end
^
SET TERM ; ^