Get Data of a month from a dated column - oracle

Respected all I want to bring data from a dated column with input of a Month like I have a column in database which type is dated but I want data only mentioning just month and year I tried but got errors please check my query
SELECT
M.INV_NUM, M.GD_NUM, M.INV_DATE, M.QTY1,
D.ITEM_CODE, D.HS_CODE, R.QNTY, R.waste_per,
R.WASTE_QNTY, (R.WASTE_QNTY+R.QNTY) TOTAL_CONSUMED
FROM
DOCT_EXPT_SALE_MST M,
DOCT_EXPT_SALE_RAW R,
DOCT_EXPT_SALE_DTL D
WHERE
R.SALE_DET_ID = D.SALE_DET_ID
AND D.SALE_ID = M.SALE_ID
AND M.INV_DATE BETWEEN TO_DATE(TRUNC('072022','MMYYYY')) AND TO_DATE(TRUNC('072022','MMYYYY'))--TO_NUMBER(TO_DATE(TO_CHAR('01072022','DDMMYYYY'))) AND TO_NUMBER(TO_DATE(TO_CHAR('31072022','DDMMYYYY')))
AND M.COMP_CODE = 3;
I tried many things but all is gone in vain. If anybody help me on this, I shall be very thankful my database is 11g

If you are being passed the string '072022' then you can do:
AND M.INV_DATE >= TO_DATE('072022','MMYYYY')
AND M.INV_DATE < ADD_MONTHS(TO_DATE('072022','MMYYYY'), 1)
The TO_DATE('072022','MMYYYY') clause will give you midnight on the first day of that month, so 2022-07-01 00:00:00.
The ADD_MONTHS(TO_DATE('072022','MMYYYY'), 1) clause will take that date and add one month, giving 2022-08-01 00:00:00.
The two comparisons will then find all dates in your column which are greater than or equal to 2022-07-01 00:00:00, and less that 2022-08-01 00:00:00 - which is all possible dates and times during that month.
So your query would be (switching to ANSI joins!):
SELECT
M.INV_NUM, M.GD_NUM, M.INV_DATE, M.QTY1,
D.ITEM_CODE, D.HS_CODE, R.QNTY, R.waste_per,
R.WASTE_QNTY, (R.WASTE_QNTY+R.QNTY) TOTAL_CONSUMED
FROM
DOCT_EXPT_SALE_MST M
JOIN
DOCT_EXPT_SALE_DTL D ON D.SALE_ID = M.SALE_ID
JOIN
DOCT_EXPT_SALE_RAW R ON R.SALE_DET_ID = D.SALE_DET_ID
WHERE
M.INV_DATE >= TO_DATE('072022','MMYYYY')
AND M.INV_DATE < ADD_MONTHS(TO_DATE('072022','MMYYYY'), 1)
AND M.COMP_CODE = 3;

Related

Date range comparison in CQ using XPATH

I'm using the following query to get nodes based on last modified date in CQ.
/jcr:root/content/scaffoldes/properties//*[#jcr:primaryType = 'nt:unstructured' and (#sling:resourceType = 'acme/components/content/scaffoldItem' or #sling:resourceType = 'acme-core/components/data/property') and #jcr:content/cq:lastModified >= xs:dateTime('2000-01-01T00:00:00.000-08:00') and #jcr:content/cq:lastModified < xs:dateTime('2014-12-31T00:00:00.000-08:00') and not(#isHidden)] order by #jcr:score
we have used
http://localhost:4502/crx/explorer/ui/search.jsp
To test this query. But, even after giving a huge date range (2000 - 2016) this query is returning nothing.
But If we remove the date range part, this query returns nodes.
Any pointer to correct this would be helpful.
Thanks and Regards,
San
Notes
The date string is create with the following code:
Calendar cal = Calendar.getInstance();
cal.setTime(start);
String startDate = ValueFactoryImpl.getInstance().createValue(cal).getString();
Sorry for any confusion caused. I found that the node which I'm trying to query doesn't have a cq:lastModified property. So modified the query to include the cq:lastReplicated in the condition.
... and ((#jcr:content/cq:lastModified >= xs:dateTime('2000-01-01T00:00:00.000-08:00') and #jcr:content/cq:lastModified < xs:dateTime('2016-02-11T15:52:57.090-08:00')) or (#jcr:content/cq:lastReplicated >= xs:dateTime('2000-01-01T00:00:00.000-08:00') and #jcr:content/cq:lastReplicated < xs:dateTime('2016-02-11T15:52:57.090-08:00'))) and ...

Oracle Apex get Multiple results from checkboxes

DB = Oracle 11g
Apex = 4.2.6
In the form I have various items which all work great. However I now have a set of check boxes(:P14_DAYS) one for each day of the week.
What I need to do is get all records between :P14_START_DATE :P14_END_DATE, but only within the days select that's checked.
Below is also a sample of the DATE_SETS table
http://i.stack.imgur.com/YAckN.png
so for example
dates 01-AUG-14 - 5-AUG-14 But only require Sundays AND Mondays date would bring back 2 refs.
BEGIN
UPDATE MD_TS_DETAIL
SET job_for = :P14_JOBFORTEM,
job_type_id = :P14_JOB_TYPE_VALUE,
account_id = :P14_ACC_VAL,
qty = :P14_HRS,
rio = :P14_RIO,
post_code = :P14_POSTCODE
WHERE id IN (SELECT D.id
FROM MD_TS_MAST M
LEFT JOIN MD_TS_DETAIL D
ON M.mast_id = D.md_id
LEFT JOIN DATE_SETS
ON ms_date = dt
WHERE eng_id = :P14_ENG_VAL
AND ms_date BETWEEN :P14_START_DATE AND :P14_END_DATE
AND DATE_SETS.col_day = ANY instr(':'||:P14_DAYS||':',Return)
END;
Any help would be much appreciated .
I found this example: http://docs.oracle.com/cd/B31036_01/doc/appdev.22/b28839/check_box.htm#CHDBGDJH
As I can understand, when you choose some values in your checkbox list, item :P14_DAYS receives value, that contains return values of chosen elements of the LOV with delimiters. Then you need to replace this string in your query
AND DATE_SETS.col_day = ANY instr(':'||:P14_DAYS||':',Return)
with
AND instr(':'||:P14_DAYS||':', ':'||DATE_SETS.col_day||':') > 0
Here function instr searches substring DATE_SETS.col_day in string :P14_DAYS. It returns position of substring if substring was found or 0, if not found. Then you compare result of function with 0, and if result > 0, it means that DATE_SETS.col_day is among selected values.

How stock a numeric value (diff of 2 date)

I've to calculate the différence between two Dates : TODAY() and DATE_DEB_VAC.
With Oracle, it's kinda easy : TODAY()-DATE_DEB_VAC -> give the number of day between those 2 date.
But I've to do it with in an ETL (GENIO). I've a column to stock it like that :
NUMBER_DAY_DIFF (NUMBER 10) = TODAY()-DATE_DEB_VAC. But it's impossible to stock it cause it's 2 date.
How can i do this ? :(
You can try the val function of GENIO ETL
VAL(TODAY()-DATE_DEB_VAC)
this is equivalent to to_numbre in Oracle
NUMBER_DAY_DIFF (NUMBER 10) = DATEDIFF (TODAY; DATE_DEB_VAC)
Should give you what you need.

Linq assign values from one table into another

I am trying to lookup a value of an column from another table and later use the new looked up values in my where clause. For example, I have the following tables below
ID Name
1 Jan
2 Feb
3 March
Product Customer Start End
A C Feb March
A B Jan March
B C March Jan
In the example above, I need to query for the list of records where Start ID is greater than the End ID. For example, B-C-March-Jan is the record I am looking for.
Should I be using join? Also, if possible a query syntax would be very helpful.
My query:
var vInvalidStartEnd = from p in vRecords
where (from t in vTimePeriods where t.Name == p["Start"] select t.TID).First().Cast<int>() > (from t in vTimePeriods where t.TName == p["End"] select t.ID).First().Cast<int>()
select new
{
Product = p["Product"],
Location = p["Location"],
Start = p["Start"],
End = p["End"]
};
Thanks
Assuming ID defines what name is later than another. Tim's issue in comments is probably because, first, it's unusual to use the name value as your link instead of the ID, and second, ID is a poor indication of which month is greater than another. If I had to use month names the way you are, I would probably have an id, a name, and then an order value in the vTimePeriods table.
from p in vRecords
join start in vTimePeriods on p["Start"] equals start["Name"]
join end in vTimePeriods on p["End"] equals end["Name"]
where (int)end["ID"] < (int)start["ID"]
select new
{
Product = p["Product"],
Location = p["Location"],
Start = p["Start"],
End = p["End"]
};
I don't know the specifics of Linq to Dataset, but it would look something like that.

Calculating holidays

A number of holidays move around from year to year. For example, in Canada Victoria day (aka the May two-four weekend) is the Monday before May 25th, or Thanksgiving is the 2nd Monday of October (in Canada).
I've been using variations on this Linq query to get the date of a holiday for a given year:
var year = 2011;
var month = 10;
var dow = DayOfWeek.Monday;
var instance = 2;
var day = (from d in Enumerable.Range(1,DateTime.DaysInMonth(year,month))
let sample = new DateTime(year,month,d)
where sample.DayOfWeek == dow
select sample).Skip(instance-1).Take(1);
While this works, and is easy enough to understand, I can imagine there is a more elegant way of making this calculation versus this brute force approach.
Of course this doesn't touch on holidays such as Easter and the many other lunar based dates.
And it gets complicated if you have to consider non-christian holidays. For example, jewish holidays are based on the jewish calender..
Maybe not so elegant, but more error prone - you can just add a table of all relevant holidays for the next 100 years.
int margin = (int)dow - (int)new DateTime(year, month, 1).DayOfWeek;
if (margin < 0) margin = 7 + margin;
int dayOfMonth = margin + 7*(instance - 1) //this is for 0-based day number, add 1 if you need 1-based. instance is considered to be 1-based
Please note that I wrote it without trying to compile, so it is to give the idea, but may require some clean up. Hope this helps!

Resources