Click here to Skip to main content
15,867,835 members
Home / Discussions / Database
   

Database

 
AnswerRe: How to get this result in oracle database? Pin
Mycroft Holmes22-May-22 13:18
professionalMycroft Holmes22-May-22 13:18 
QuestionSQL SERVER STORE PROCEDURE Pin
Luis M. Rojas28-Apr-22 3:45
Luis M. Rojas28-Apr-22 3:45 
AnswerRe: SQL SERVER STORE PROCEDURE Pin
Richard Deeming28-Apr-22 4:34
mveRichard Deeming28-Apr-22 4:34 
AnswerRe: SQL SERVER STORE PROCEDURE Pin
Mycroft Holmes28-Apr-22 11:59
professionalMycroft Holmes28-Apr-22 11:59 
GeneralRe: SQL SERVER STORE PROCEDURE Pin
jschell8-May-22 8:07
jschell8-May-22 8:07 
QuestionGiven two dates, count the number of dates in the range that is within month X Pin
Jame_T13-Apr-22 3:43
Jame_T13-Apr-22 3:43 
AnswerRe: Given two dates, count the number of dates in the range that is within month X Pin
Craig Robbins13-Apr-22 4:10
Craig Robbins13-Apr-22 4:10 
AnswerRe: Given two dates, count the number of dates in the range that is within month X Pin
CHill6020-Apr-22 7:04
mveCHill6020-Apr-22 7:04 
As you have not shared your attempt at solving this for yourself, nor responded to Craig, I am only going to give you hints to a possible solution. For my test data I used this
SQL
declare @demo table (startdate date, enddate date)
insert into @demo (startdate, enddate) values
('2022-03-01', '2022-04-10'),
('2021-12-01', '2022-03-11'),
('2022-01-01', '2022-04-05');
I also hard-coded the start and end dates for the month I am interested in
SQL
declare @1stDay date = '2022-04-01';
declare @LastDay date = '2022-04-30';
I then wrote some sql that would convert the dates I had on the table to only those that fell into the month I am looking at. E.g. Something like this
SQL
select startdate, enddate

	,case	when startdate < @1stDay then @1stDay 
			when startdate > @lastDay then @LastDay
			else startdate end as AmendedStartDate
	,case	when enddate < @1stDay then @1stDay
			when enddate > @LastDay then @LastDay
			else enddate end as AmendedEndDate

from @demo;
I then used those Amended dates in a datediff calculation to get the number of days in each range that fell in April 2022.

This approach is flawed - in that I get 9, 0 and 4 as the results instead of 10, 0, 5. I will leave that as an exercise for you to sort out. I also coded this in MSSQL so you may need to make minor syntactical changes
QuestionBest practice for creating a limited access ms-sql user ? Pin
David Mujica12-Apr-22 11:12
David Mujica12-Apr-22 11:12 
AnswerRe: Best practice for creating a limited access ms-sql user ? Pin
jschell8-May-22 8:11
jschell8-May-22 8:11 
QuestionMysql How to sort row ORDER BY another query? Pin
Zac Ang3-Apr-22 10:45
Zac Ang3-Apr-22 10:45 
SuggestionRe: Mysql How to sort row ORDER BY another query? Pin
Richard Deeming3-Apr-22 21:46
mveRichard Deeming3-Apr-22 21:46 
AnswerRe: Mysql How to sort row ORDER BY another query? Pin
CHill606-Apr-22 2:57
mveCHill606-Apr-22 2:57 
QuestionFilter data before lookup(join) two collections in mongodb Pin
85510-Mar-22 4:20
85510-Mar-22 4:20 
Rant[REPOST] Filter data before lookup(join) two collections in mongodb Pin
Richard Deeming10-Mar-22 4:51
mveRichard Deeming10-Mar-22 4:51 
GeneralRe: [REPOST] Filter data before lookup(join) two collections in mongodb Pin
85510-Mar-22 5:23
85510-Mar-22 5:23 
GeneralRe: [REPOST] Filter data before lookup(join) two collections in mongodb Pin
Richard Deeming10-Mar-22 6:26
mveRichard Deeming10-Mar-22 6:26 
Question[MySQL] Failed to set datadir Pin
chipp_zanuff1-Mar-22 7:54
chipp_zanuff1-Mar-22 7:54 
AnswerRe: [MySQL] Failed to set datadir Pin
Victor Nijegorodov1-Mar-22 8:39
Victor Nijegorodov1-Mar-22 8:39 
GeneralRe: [MySQL] Failed to set datadir Pin
chipp_zanuff1-Mar-22 17:42
chipp_zanuff1-Mar-22 17:42 
GeneralRe: [MySQL] Failed to set datadir Pin
Victor Nijegorodov1-Mar-22 22:42
Victor Nijegorodov1-Mar-22 22:42 
AnswerRe: [MySQL] Failed to set datadir Pin
Richard MacCutchan1-Mar-22 22:45
mveRichard MacCutchan1-Mar-22 22:45 
GeneralRe: [MySQL] Failed to set datadir Pin
chipp_zanuff2-Mar-22 0:35
chipp_zanuff2-Mar-22 0:35 
GeneralRe: [MySQL] Failed to set datadir Pin
Richard MacCutchan2-Mar-22 0:47
mveRichard MacCutchan2-Mar-22 0:47 
GeneralRe: [MySQL] Failed to set datadir Pin
chipp_zanuff2-Mar-22 23:37
chipp_zanuff2-Mar-22 23:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.