I have the following from and to dates and need to list using a dynamic sql query only the 3 dates that are mentioned below in netezza database
From To
20120603 20120831
Required Result:
20120702
20120703
20120801
Is there a possibility using dynamic SQL query for netezza that dates in a user specified range can be generated.
I'm not sue I understand your question, but I think you want
WHERE From IS NULL
u can try something like
select * from table where date in (20120702,20120703,20120801)
Related
I am trying to run a select statement on a table acct id. My account ID's can have the following pattern which is the one I am having issues with: 2733R9087813964
How do I run a SELECT Statement on this column and extract only the numeric portion after the "R"?
So the result in this scenario would be: 9087813964
Any help would be appreciated.
try
SELECT Substr(ACC_ID, Position('R' IN ACC_ID) +1 )
FROM ACCOUNT
I'm looking to find a way to add a day to a date in both Postgres and SQL Server so I don't have to add an if condition checking which database the server is running
DATEADD(day, 1, STOP_DATE)
doesn't work in PostgreSQL &
STOP_DATE + 1
doesnt work in sql server
Overall, it is not a good idea to try to write SQL code using syntax that is common on both SQL Server and Postgres. You are severely limiting yourself and will sooner or later come across a query that runs too slowly because it doesn't use syntax specific to one of the DBMS.
For example, with your approach you are artificially refusing to use lateral joins, because their syntax is different in Postgres (LATERAL JOIN) and SQL Server (CROSS/OUTER APPLY).
Back to your question.
You can add an integer value to a date value in Postgres and to datetime value in SQL Server.
SQL Server
CREATE TABLE T(d datetime);
INSERT INTO T VALUES ('2020-01-01');
SELECT
d, d+1 AS NextDay
FROM T
http://sqlfiddle.com/#!18/d519d9/1
This will not work with date or datetime2 data types in SQL Server, only datetime.
Postgres
CREATE TABLE T(d date);
INSERT INTO T VALUES ('2020-01-01');
SELECT
d, d+1 AS NextDay
FROM T
http://sqlfiddle.com/#!17/b9670/2
I don't know if it will work with other data types.
Define a function in PostgreSQL that works like the sql server function.
Edit:
can't pass day
Create a function with the same name on each database system that adds a day accordingly.
I am having an issue in writing on the SQL for ETL purpose.
My Oracle DB has a column A that holds 999999999997259 or 4121.375515. I need to transform this value to decimal(15,6). The datatype decimal(15,6) is on the target where the data will be loaded.
Any suggestions.
TIA
Following is the way to round the value to 6 decimal place. Condition: It should contain
valid values.
select cast(round(ColumnaA,6) as DECIMAL(15,6)) from table;
I want to access data from database between two dates, Date format is yyyy/mm/dd. I tried a lot of queries but not succeed.
Try following query to get data between the range:
SELECT *
FROM Table_Name
WHERE From_date >= '2016-08-01' AND
To_date <= '2016-08-30'
IF you are using just vanilla sql it would just be something alone the lines of
select x from table where datecolumn between 'xdate' and 'ydate'.
Do you have a date column in the table you are looking at correct?
I have a simple sqlite database with several tables like this
schedule_20140824
schedule_20140825
schedule_20140826
...
How do I generate a select statement into a table for given a date?
For example, let's say today is the 26th and I wanted my app to access today's schedule table. What is the correct way to do the following?
SELECT * FROM 'schedule_'||strftime('%Y%m%d','now');
Any advice would be appreciated. Thanks!
SQLite itself cannot generate SQL dynamically.
You have to do this in your programming language:
db.execute("SELECT * FROM schedule_" + date)