Oracle date column value as 0000 - sql

We need to store 00-00-00 in date datatype in Oracle column. But Oracle doesn't allow.
Are there alternate representations or ways to store it?

Oracle does allow you do insert the date 1st January 1AD:
INSERT INTO table_name ( date_column ) VALUES ( DATE '0001-01-01' );

I don't know if this is relevant, but I was once "required" to store 0th April 1996, 0th 1996, etc.. The real requirement was that these were fiscal transactions that could not be assigned to a single day or month respectively (e.g. journal vouchers).
The solution was to use real dates (1st April 1996, 1st Jan 1996), and to add another column that gave the "scope" of the record -- "D", "M", "Q", "Y".
So if all the transactions for 1st Apr 1996 were required, a date_scope = 'D' predicate could be added to my_date = date '1996-04-01' to ensure that only daily transactions were retrieved.
If all the transactions for April 1996 were required ...
my_date between date '1996-04-01' and date '1996-04-30' and
date_scope in ('D','M')

Related

Specific Month-day select statement query

I would like to select from a table where the date falls within a specific time each year f.e:
select * from Customer where date >= August 15th and date <= December 20th
Since this will be for a report that runs every year, I do not want to hardcore the date as I will have to change it every year. I would like to have it dynamic to pick the date from August 15th to December 20th of the current year.
I have the below query where I can retrieve the Month and Date:
SELECT DATENAME(month, date) AS Month,DATENAME(day, date) AS Day from Customer
However, I am struggling to have this selection date range.
TIA
In SQL SERVER 2017
maybe this can help you:
SELECT * FROM Customer WHERE date BETWEEN
CONVERT(DATETIME,CONCAT(YEAR(GETDATE()),'08','15')) AND
CONVERT(DATETIME,CONCAT(YEAR(GETDATE()),'12','20'))
This add the current year to a concatenated date you want, then convert it all into datetime type..

SQL- How to filter registers where date is prior to previous month beginning?

I have this query with a SELECT statement and I need to add to my WHERE clause the condition that the date must be prior to the previous month beginning.
SELECT columnA, columnB
FROM TableX
WHERE columnA=20
For example the current date belongs to October so I need to filter the registers where date belongs to September or October from this year.
Let's say we are in December 2022, I would need to filter the registers whose date belongs to November 2022 or December 2022.
I am using an Oracle database.
How can I do it?
It should be something among the lines of:
SELECT columnA, columnB
FROM TableX
WHERE columnA = 20
AND <your_date_column> BETWEEN TRUNC(ADD_MONTHS(SYSDATE,-1),'MM') AND TRUNC(LAST_DAY(SYSDATE),'MM');

SELECT dates within one season (between two dates, of any year)

Is it possible in Oracle SQL to select rows where one column is a date, and we want this date to be between two dates irrespective of the year.
For example if the interval is summer, i'd want to be able to have any dates bewteen 20th of june and 22nd of september, where the year can be 1999, 2000, 2018, 2897 etc.
You can convert to a string of the form MM-DD and compare that:
where to_char(col, 'MM-DD') between '06-20' and '09-22'

What method can I use to get a different date value for a stored field in my database?

I am working on a project that is asking me to return different date values based on the scenario and I am not quite sure how to write this out. I think that I'm just not understanding how to apply the logic:
PAYFREQ is A then TRANS_DATE is 1st of the Year of COMPEFFDT
PAYFREQ is M then TRANS_DATE is 1st of the Month of COMPEFFDT
PAYFREQ is B then 1st day of the biweekly period ending with COMPEFFDT
PAYFREQ <> A and the only non-zero FIC amount for a calendar year has COMPEFFDT of December 31, then TRANS DATE is 1st of the Year of COMPEFFDT
Can anyone give me at least a base starting point in how to formulate this statement?
Assuming this is in a query, try the SWITCH statement. I'm not sure what you mean by the "1st of year of COMPEFFDT" though.
SELECT SWITCH (
PAYFREQ = "A", "1st of year of COMPEFFDT",
PAYFREQ = "M", "1st of the Month of COMPEFFDT",
...
) AS Result
Also, you should look at the guide for submitted a new question.

Postgresql max date in dataset for each month

I have a table with the following columns (in addition to others):
name char
tanggal date
Rows are inserted into this table each day.
How can I get the formatted name for the max date of each month,
for example:
Jan 31, Feb 28, Mar 31, Apr 30,...
I am using Postgresql 8.3
You could use extract to get the month of the date. From there on, it's a straight forward group by query:
SELECT MAX(tanggal)
FROM mytable
GROUP BY EXTRACT (MONTH FROM tanggal)