I am using following query in Teradata:
SELECT dt.CUSTOMERID, dt.TEXT, dt.NUMER, dt.DESCRIPTION
FROM user.sbcustomer_dim dt
WHERE dt.CUSTOMERID IN( SELECT bt.CUSTOMER_ID FROM user.SBCustomer bt);
And it is reporting following error:
Failure 3706 Syntax error: expected something between the 'SELECT' keyword and the 'bt' keyword.
Statement# 1, Info =122*
And If I remove alias from IN() clause, query works fine.
Is alias in subquery not supported in Teradata? (Teradata version: 13.10.00.14)
If you read the error message carefully you will notice that bt is a keyword (shortcut for BEGIN TRANSACTION).
Simply change it to something else.
Related
I already downloaded the latest SQLite.dll from SQLite Download Page and try to load it using TFDPhysDriverLink.VendorLib
But when I run the app, which contains the following code:
procedure TForm1.FormCreate(Sender: TObject);
begin
FDConnection1.Close;
FDPhysSQLiteDriverLink1.Release;
FDPhysSQLiteDriverLink1.VendorLib:= 'Path\SQLite3.dll';
FDQuery1.Open('SELECT *, ROW_NUMBER() OVER() Col FROM TableName');
end;
It throws:
[FireDAC][Phys][SQLite] ERROR: near "(": syntax error
Which means that the window function ROW_NUMBER() is not recognized.
What I'm doing wrong?
How can I force FireDAC to use the latest SQLite.dll?
SQLite do not support ROW_NUMBER.
Look at the answers for this question, you'll probably find something to replace ROW_NUMBER.
If you get this error, then the SQlite3.dll was loaded just fine.
Just use the RowID field, which is always existing for any standard SQLite3 table - unless you explicitly created them with CREATE TABLE WITHOUT ROWID statement.
So I would just write:
FDQuery1.Open('SELECT *, RowID FROM TableName');
Note that if there is an explicit INTEGER PRIMARY KEY column in your table, it will in fact map the internal RowID column. Check the SQLite3 documentation for how this works.
I have a simple SQL that need to call RedShift through ODBC.
The SQL is like this
SELECT id as Tag From SomeView
This just not working. It gives me the error
DataSource.Error: ODBC: ERROR [42601] [Amazon][Amazon Redshift] (30) Error occurred while trying to execute a query: [SQLState 42601] ERROR: syntax error at or near "'Tag'"
LINE 1: Select id As Tag From SomeView
Details:DataSourceKind=OdbcDataSourcePath=dsn=Amazon Redshift ODBC DSNOdbcErrors=Table
I tried
SELECT id as 'Tag' From SomeView
SELECT id Tag From SomeView
SELECT id 'Tag' From SomeView
None of them work. Only the one with no rename works.
SELECT id From SomeView
Why is that???
Try
SELECT id "Tag" From SomeView
Tag is a reserved word in Redshift, if you like to use reserved words as column names or aliases you need to use delimited identifiers (double quotes).
I'm using SQlite in an Windows application (done with Visual C#); while inserting columns into the table I'm getting the following error:
Error while executing SQL query on database 'database': row value misused
The following is my insertion query:
INSERT INTO d_logindetails (userid,registration_no,logintime,expected_logout,machinesno,is_uploaded)VALUES (234,'1233',CURRENT_TIMESTAMP,(CURRENT_TIMESTAMP,'+60 minutes'),'s12452',0);
'+60 minutes' is just a string.
When used with the built-in date/time functions, it is interpreted as a modifier.
So to do this computation, you have to call such a function:
INSERT ... VALUES (..., CURRENT_TIMESTAMP, datetime('now', '+60 minutes'), ...);
I'm guessing it's the part where you have the following:
(CURRENT_TIMESTAMP,'+60 minutes')
Personally I'd just do:
dateadd(HOUR, 1, getdate())
I'm using sqlte3.8.8, trying to create a trigger to clean old data. Here is the SQL that I put in:
CREATE TRIGGER "main"."NewTrigger" AFTER INSERT ON "historydata"
BEGIN
delete from historydata where id in (select id from historydata order by id limit 100000);
vacuum;
END;
But I got Syntax error on "vacuum;".However, it works fine in sqlite command line.
Is it the case that "vacuum" cannot be used in a trigger?
The documentation shows that only UPDATE/INSERT/DELETE/SELECT statements are allowed in a trigger body.
I use bash to access a sqlite3 database.
Is there a way to get the last inserted id that way, because on the sqlite-webpage (http://www.sqlite.org/c3ref/last_insert_rowid.html) I only see the C-API, but no way to do it on the command line.
The function last_insert_rowid() does not work either:
sqlite> last_insert_rowid();
SQL error: near "last_insert_rowid": syntax error
should be
select last_insert_rowid();