Sum up between certain dates-tsql query
Hi,
We have a following scenario,
DATE
MONTH start
MONTH end
IS BUSINESS DAY
2014-02-23
2014-02-01
2014-02-28
0
2014-02-24
2014-02-01
2014-02-28
1
2014-02-28
2014-02-01
2014-02-28
1
For example, if date 2014-02023 is chosen, then we need to sum total business days for the whole month. Table is similar as above,
select * from A where date = '2014-02-23'. If we choose this day, then need to sum for column "is business day" for all rows with month end of '2014-02-28, month start of '2014-02-01' .
Is ther any easier way to calculate this? Appreciate for your feedback.
If you have a date (or datetime) in a variable named @TestDate, then this should give you the result you want.
Select Sum([IS BUSINESS DAY]) As BusinessDays
From YourTable
Where [Month Start] = Cast(Convert(char(6), @TestDate, 112) + '01' As Date)
Tom
Similar Messages
-
How to determine if first date in multi record dataset is between certain date range.
Post Author: wal
CA Forum: Formula
I am trying to determine how many patients enrolled in our database from 1/1/2000 to 12/31/2003. The "ltvisit" table has a field called "visit_date" which is the field I am working with to determine. How do I code in crystal reports to find out if the FIRST visit_date record (FIRST VISIT) was between 1/1/2000 and 12/31/2003. Thanks.Post Author: yangster
CA Forum: Formula
are you creating this in a command or you just bringing in the information from a single table or whatwhat you need to do is do a simple queary to pull in the first record from the patientonce you have that date then you then can do a simple in statement between your 2 dates -
Lost all mail between certain dates
I've lost all my mail between September 30 and January 14 in the in box and the sent mail.
This is across the 3 accounts I have set up.
The trash box holds nothing prior to January 14th.
All very confusing, and even more annoying. Any of you smart people got any idea what could be causing this, or more importantly how I could retrieve the files.
Many ThanksLet's force an overall reindexing via the removal of the Envelope Index since you say it is spread across all accounts. Note the special instructions when forcing the reindexing of IMAP or Exchange accounts in the following:
http://docs.info.apple.com/article.html?path=Mail/3.0/en/14019.html
This will force the reindexing of all the POP mailboxes and any On My Mac mailboxes. With regard to the IMAP account, the practical result of this action of removing the account folder, is that with the IMAP account still set up in the Preferences, Mail will connect to the IMAP server and create a new account folder, and while doing so will index the messages in the mailbox folders of the IMAP account on the server. Not removing the IMAP account folders when removing the Envelope Index file may lead to strange results -- have you by any chance ever forced a reindexing by removing the Envelope Index? This could have happened if you ever used a suggestion to remove all files except folders to cure a problem some people encountered when upgrading to 10.5.6 from 10.4.11 (was not the preferred solution however.
May I assume that all standard mailboxes related to the IMAP account are stored on the server, as would be normal?
Keep me posted.
Ernie -
Between specific dates per month SQL
All,
I am creating a query that I need to pull between certain dates for each month. If this was a one time thing, I could do the simple between call, but.... What I am trying to do is have a query from our system run at the end of each month to pull the pay period dates. For example, for a pay run period between 24-JAN-2012 and 23-FEB-2012 the query would pull those dates at the end of FEB, and the same for end of MAR that would pull between 24-FEB-2012 and 23-MAR-2012,
and so on, and so on.
CREATE TABLE ps_paycal
(emplid NUMBER (6) PRIMARY KEY
, name VARCHAR2 (12)
, frozen_dt date
INSERT INTO ps_employees (emplid,name,date)
VALUES (111111,'JOHN DOE','24-JAN-2012');
INSERT INTO ps_employees (emplid,name,date)
VALUES (111111,'JOHN DOE','23-FEB-2012');
INSERT INTO ps_employees (emplid,name,date)
VALUES (111111,'JOHN DOE','24-FEB-2012');
INSERT INTO ps_employees (emplid,name,date)
VALUES (111111,'JOHN DOE','23-MAR-2012');
INSERT INTO ps_employees (emplid,name,date)
VALUES (111111,'JOHN DOE','24-MAR-2012');
INSERT INTO ps_employees (emplid,name,date)
VALUES (111111,'JOHN DOE','23-APR-2012');
Hope this makes sense. Anyway, this is Oracle 11g.
Thanks for the help!
KarstenKarsten Hilton wrote:
All,
I am creating a query that I need to pull between certain dates for each month. If this was a one time thing, I could do the simple between call, but.... What I am trying to do is have a query from our system run at the end of each month to pull the pay period dates. For example, for a pay run period between 24-JAN-2012 and 23-FEB-2012 the query would pull those dates at the end of FEB, and the same for end of MAR that would pull between 24-FEB-2012 and 23-MAR-2012,
and so on, and so on.
CREATE TABLE ps_paycal
(emplid NUMBER (6) PRIMARY KEY
, name VARCHAR2 (12)
, frozen_dt date
INSERT INTO ps_employees (emplid,name,date)
VALUES (111111,'JOHN DOE','24-JAN-2012');
INSERT INTO ps_employees (emplid,name,date)
VALUES (111111,'JOHN DOE','23-FEB-2012');
INSERT INTO ps_employees (emplid,name,date)
VALUES (111111,'JOHN DOE','24-FEB-2012');
INSERT INTO ps_employees (emplid,name,date)
VALUES (111111,'JOHN DOE','23-MAR-2012');
INSERT INTO ps_employees (emplid,name,date)
VALUES (111111,'JOHN DOE','24-MAR-2012');
INSERT INTO ps_employees (emplid,name,date)
VALUES (111111,'JOHN DOE','23-APR-2012');
Hope this makes sense. Anyway, this is Oracle 11g.
Thanks for the help!
KarstenWell, assuming that's a constant (the pay period start date being the 24th of the previous month) you could do something like this to get your pay period start / end dates.
select pay_start, add_months(pay_start, 1) - 1
from
select to_date(to_char(add_months(sysdate, -1), 'yyyy-mm') || '-24', 'yyyy-mm-dd') as pay_start
from dual
) -
Count between two dates.
dear friends
i want fetch count between two dates.
my query is like below.
SELECT (to_date('19-mar-2012','dd-mm-yyyy')-to_date('01-apr-2012','dd-mm-yyyy')) FROM dual
its given out like -13 but i want in positive mod like 13 only not '-' Sign.just use abs() function to your query to get the positive value
SELECT abs(to_date('19-mar-2012','dd-mm-yyyy')-to_date('01-apr-2012','dd-mm-yyyy')) diff FROM dual -
Selecting values between 2 dates for an SQL query report region
I have a region where im selecting between 2 dates
select hp.NAME, hp.VALUE, hp.UPDATEDATE, hp.DESCRIPTION, hp.UPDATE_COMMENT, hp.HASH, hp.IDCATEGORY
from HIST_REPORT hr, HIST_PARAM hp
where hp.dbid = hr.dbid and hr.id = :P7_ID and hp.UPDATEDATE between :P7_BDATE and :P7_EDATE
The problem is that if I have a row thats dated today (april 1) and if I set the beginning date (BDATE) to april 1 as well as the ending date (EDATE), no rows show and I would like the april 1 row to show. How can I modify my query to fix this?and hp.UPDATEDATE between :P7_BDATE
and decode(:P7_EDATE,:P7_BDATE,:P7_EDATE+1,:P7_EDATE)This assumes, though, that the time component of your items is implicitly 00:00.
Joel -
How to calculate the month difference between two date char. in Query?
Customers would like to see how many months passed between two date type of characteristics (e.g., the month difference between the current date and the scheduled delivery date in the record) and put the result into the column as KF.
We would have to grab the fiscal year/period kind of value and then do the subtraction, e.g., if the current date value is 2/28/2008 and the scheduled delivery date value in the record is 12/01/2007, the correct result should be 2 month difference between these two date values, but could someone here give us the technical light on how to make this happen in query design?
Thanks and we will give you reward points for the correct anwsers!Hi Kevin,
The Badi is RSR_OLAP_BADI.
You can create an implementation using Transaction SE18.
The implementation is per cube and is defined in the filters.
In the Implementation you have the following methods :
1. Define : Here you will provide the Keyfigure you need as a virtual one.
2. Initilialize : Any Init Function you want to do.
3. Compute. This is called per datarecord and here you can cimpute your value.
Hope this helps.
Pralay Ahluwalia -
ABAP Query: creation of local field (Subtraction between 2 dates)
Hi,
I want to create a local field which will calculate the number of days between 2 dates (for example, document date - posting date).
What I did:
1) Created the user group in SQ03
2) Created the infoset in SQ02
3) I'm stucked at the creation of the Query in SQ01. I'm at the «Create Query: Select field screen». I clicked on Edit --> Local Field --> Create. I selected the «calculation field» attribute. I clicked on the «Complex calculation button», but I don't know how to write my formulate DOCUMENT DATE - POSTING DATE.
Thanks a lot for your help.
JulienTry these FM's to calculate difference between two dates..
DAYS_BETWEEN_TWO_DATES
LEAP_DAYS_BETWEEN_TWO_DATES
HR_SEN_CALE_DAYS_DATE
ISB_DAYS_BETWEEN_TWO_DATES
FIMA_DAYS_BETWEEN_TWO_DATES
FIMA_DAYS_BETWEEN_TWO_DATES_2
FIMA_LEAP_DAYS_BETWEEN_2_DATES
SD_DATETIME_DIFFERENCE -
How to query / list table name with certain data type?
Hi all spatials,
Sorry for the dumb question. I need to make a query that list all table name that contain certain data type, eg. SDO_georaster. How to do this ?
Many thanks in advance
damonSkip it. I figured it : using USER_TAB_COLUMNS will definitely help.
Cheers
damon -
Select Query Between two dates...
Hi Guru's,
I need a Select Query between two dates, also if the record not found for any in between date then it should return NULL or 0 ...
for Example
1. I am having two records in DB for date 2-10-2008 & 4-10-2008
2. Now suppose I have given Query for date between 1-10-2008 to 5-10-2008
Then it should return me 5 records with valid values for 2 & 4 and NULL for other 1,3,5
Thanks.Try like this:
with
t as
select date '2008-10-02' as dt, 'Record #1 (in DB)' as str from dual union all
select date '2008-10-04' as dt, 'Record #2 (in DB)' as str from dual
select v.dt, t.str
from (
select date '2008-10-01' + level - 1 as dt
from dual
connect by level <= (date '2008-10-05' - date '2008-10-01') + 1
) v
left join t
on v.dt = t.dt
order by 1 -
Certain data columns not showing up during a query
I have having trouble seeing certain data types when I search in Oracle SQL developer. Fields such as Dates and numeric values are showing as blank when I run a query. If I run the same query in SQL Plus, date values and numeric values appear.
I am using SQL developer 2.1, but this was also happening when I was using early versions such as 1.5.5
THe Database is an oracle 11g database
on my machine I have an instance of java 1.5.0_18 running but within the application there is a java 1.6, I am not sure if the 1.6 is executing the program or not.
WIndows XP service 2002 service pack 3
Edited by: user9958587 on Jan 7, 2010 3:27 AM
SELECT * FROM AsAddress which will return our address table containing dates.
Edited by: user9958587 on Jan 7, 2010 3:27 AM -
How to Calculate Sum of Difference between two dates
Hi,
I'm using BI Publisher in Siebel CRM.
In RTF template I have the following expression to calculate the Difference between dates
<?xdoxslt:date_diff( 'd' , psfn:totext(CIRGSubmittedDate,"yyyy-MM-dd","MM/dd/yyyy"), psfn:totext(Done,"yyyy-MM-dd","MM/dd/yyyy"), $_XDOLOCALE, $_XDOTIMEZONE)?>
The above expression works for me to calculate the dates.
I need to calculate the Sum of all these dates for a Group.
Want to know the Syntax for Sum function using Date_diff.
Tried the following and didn't work.
<?Sum(xdoxslt:date_diff( 'd' , psfn:totext(CIRGSubmittedDate,"yyyy-MM-dd","MM/dd/yyyy"), psfn:totext(Done,"yyyy-aMM-dd","MM/dd/yyyy"), $_XDOLOCALE, $_XDOTIMEZONE))?>
Not sure what I'm doing wrong here...
Anyone please help...
Thanks
PVHi
To break the diff between 2 dates into days, hours, minutes, sec -- you can use the following:
select to_char( created, 'dd-mon-yyyy hh24:mi:ss' ),
trunc( sysdate-created ) "Dy",
trunc( mod( (sysdate-created)*24, 24 ) ) "Hr",
trunc( mod( (sysdate-created)*24*60, 60 ) ) "Mi",
trunc( mod( (sysdate-created)*24*60*60, 60 ) ) "Sec",
to_char( sysdate, 'dd-mon-yyyy hh24:mi:ss' ),
sysdate-created "Tdy",
(sysdate-created)*24 "Thr",
(sysdate-created)*24*60 "Tmi",
(sysdate-created)*24*60*60 "Tsec"
from all_users
where rownum < 50
HTH
RangaReddy -
Hi,
Please could someone help me on how to write a query to retrieve the data between two dates.
created_date format stored in the database column: 9/18/2007 11:34:03 AM
I tried below but it didn't work
select * from work_table where created_date beween '9/18/2007' and '03/29/2008'
I get 'literal doesn't match format string'
Thanks,date datatype is nls dependent -> folllows the nls_date_format database parameter setting inherited by your session.
Making it short you'll be always safe if you
select * from work_table where created_date beween to_date('9/18/2007','MM/DD/YYYY') and to_date('03/29/2008','MM/DD/YYYY')Having the time component included you must add + 1 - 1 / 24 / 60 / 60 (plus one day minus one second) to the upper limit if you want to include the last day as a whole
*** not tested
Regards
Etbin -
Query for between two dates.
Hi,
I've a column of date, and I want to select the records between two dates, the output of this columns is: 08/19/2003 2:11:00 AM
My query is:
SELECT DTM FROM ITEM
WHERE DTM BETWEEN '07/01/2012' AND '07/15/2012'
Please help.
Thanks,>
I've a column of date, and I want to select the records between two dates, the output of this columns is: 08/19/2003 2:11:00 AM
My query is:
SELECT DTM FROM ITEM
WHERE DTM BETWEEN '07/01/2012' AND '07/15/2012'
Please help.
>
Help with what? You didn't ask a question or indicate if you are having a problem of some sort.
Did you need to know how to use TO_DATE instead of literals in the WHERE clause?
SELECT DTM FROM ITEM
WHERE DTM BETWEEN TO_DATE('07/01/2012', 'MM/DD/YYYY') AND TO_DATE('07/15/2012', 'MM/DD/YYYY'); -
Query to adpatches applied after certain date
Hello,
would anyone help me in select a query to find all adpatches applied after certain date?
for example all adpatches applied after jan 2010.
thanks in advanceHi,
Query AD_BUGS table (CREATION_DATE column) -- See eTRM for details about the table.
eTRM
http://etrm.oracle.com/pls/etrm/etrm_search.search
You could also get the same from OAM.
Thanks,
Hussein
Maybe you are looking for
-
Is it possible to add groups in RDP file without opening it?
We are using row-wise initalization in OBIEE 10.1.3.4. Are customers would like to add custom groups for diffenrent people so they can share dashboards. The problem is that we don't want them to touch RDP file manually. And in my knowledge the groups
-
Acrobat 9 standard-new hard drive- how to reinstall
I had acrobat 9 standard on my old hard-drive. It crashed and now I want to reinstall/download to my new hard drive. How do I do this? In my account I see the product but can't download it. I can see the serial number. Thanks
-
Capturing the output of a os command line
I need to capture the output of a os command line executed from one java program and I don't know how can do it. For example: Runtime.getRuntime().exec("hostid");
-
Error while creating concurrent workflow instances with dynamic participant
Hi All, I have a workflow which has 3 interactive activites. The second interactive activity has requires approval of atleast 3 users to proceed. The participants are also not known in advance and are created dynamically by creating the directory ses
-
How to pull up contact when sending new mail
Is there anyway to show contacts when sending a new e mail. Example on windows it will sow all contacts and then click on the ones you want to send to. Is there anyway to do this using Macbook Pro with Lion 10,7.4