Click here to Skip to main content
14,742,842 members
Home » Discussions » Database
   

Database

 
GeneralRe: vb.net connection to a firebird database Pin
Member 767827623-Sep-19 12:06
MemberMember 767827623-Sep-19 12:06 
GeneralRe: vb.net connection to a firebird database Pin
Member 767827623-Sep-19 17:16
MemberMember 767827623-Sep-19 17:16 
GeneralMessage Closed Pin
1-Oct-19 16:26
Memberhayac h1-Oct-19 16:26 
QuestionMoving from access DB to Oracle to calculate average upon request Pin
Member 1447460719-Sep-19 12:12
MemberMember 1447460719-Sep-19 12:12 
AnswerRe: Moving from access DB to Oracle to calculate average upon request Pin
Gerry Schmitz19-Sep-19 13:26
mveGerry Schmitz19-Sep-19 13:26 
QuestionMySQL database Pin
Alboyz17-Sep-19 17:46
MemberAlboyz17-Sep-19 17:46 
AnswerRe: MySQL database Pin
#realJSOP18-Sep-19 2:08
mva#realJSOP18-Sep-19 2:08 
GeneralRe: MySQL database Pin
Alboyz18-Sep-19 17:58
MemberAlboyz18-Sep-19 17:58 
AnswerRe: MySQL database Pin
Mycroft Holmes18-Sep-19 13:44
professionalMycroft Holmes18-Sep-19 13:44 
GeneralRe: MySQL database Pin
Alboyz18-Sep-19 17:58
MemberAlboyz18-Sep-19 17:58 
QuestionDatabase suddenly slow Pin
Super Lloyd17-Sep-19 16:39
MemberSuper Lloyd17-Sep-19 16:39 
AnswerRe: Database suddenly slow Pin
CHill6018-Sep-19 1:05
mveCHill6018-Sep-19 1:05 
GeneralRe: Database suddenly slow Pin
Super Lloyd18-Sep-19 21:47
MemberSuper Lloyd18-Sep-19 21:47 
AnswerRe: Database suddenly slow Pin
Richard Deeming18-Sep-19 2:01
mveRichard Deeming18-Sep-19 2:01 
GeneralRe: Database suddenly slow Pin
Super Lloyd18-Sep-19 21:47
MemberSuper Lloyd18-Sep-19 21:47 
GeneralRe: Database suddenly slow Pin
Mycroft Holmes19-Sep-19 14:14
professionalMycroft Holmes19-Sep-19 14:14 
AnswerRe: Database suddenly slow Pin
Member 1240381730-Dec-19 0:35
MemberMember 1240381730-Dec-19 0:35 
QuestionI need this windows odbc driver Pin
Member 1458760611-Sep-19 9:00
MemberMember 1458760611-Sep-19 9:00 
AnswerRe: I need this windows odbc driver Pin
OriginalGriff11-Sep-19 9:01
mveOriginalGriff11-Sep-19 9:01 
GeneralRe: I need this windows odbc driver Pin
Member 1458760611-Sep-19 9:16
MemberMember 1458760611-Sep-19 9:16 
AnswerRe: I need this windows odbc driver Pin
Maciej Los11-Sep-19 9:47
mveMaciej Los11-Sep-19 9:47 
QuestionLooking for some assistance with a query Pin
FrankLepkowski10-Sep-19 10:50
MemberFrankLepkowski10-Sep-19 10:50 
AnswerRe: Looking for some assistance with a query Pin
MadMyche10-Sep-19 12:12
mveMadMyche10-Sep-19 12:12 
A couple of tweaks is all you are going to need:

Using an INNER JOIN requires matching record to be in both tables.
To get all records from one table regardless if it matches or not you would use either a LEFTRIGHT JOIN. As you want all the records from the second table in the ON connector it would be a RIGHT JOIN

The second thing is dealing with returning 0 if no records match. Relatively easy, just slap an ISNULL (or COALESCE for ANSI SQL) with 0 as the null replacement.

My first attempt at this came up with
SELECT m.LoopCode
,       m.Chopper
,       Total_BRKS  = IsNull(Sum(s.BRKS), 0)
,       Total_BBOH  = IsNull(Sum(s.BBOH), 0)
,       Avg_DTAB        = IsNull(Avg(s.DTAB), 0)

FROM        @ShiftData          s
RIGHT JOIN @MapBushingData  m ON s.[Position] = m.LoopCode

WHERE ( s.ShiftDate >= cast('02/03/2011' as date)
    AND     s.ShiftDate <= cast('03/04/2013' as date)
)
OR  s.ShiftDate IS NULL

GROUP BY m.Chopper,m.LoopCode
And in testing I found out that IF there is a matched record BUT the date was out of range it would not return the record.
If this is desired; great.
If not, we are going to tweak how the data is JOINed together by relocating the WHERE clauses to also be part of the JOIN connections. And this is what I came up with
DECLARE @ShiftData TABLE (ndx int identity(1,1) not null, Position int, ShiftDate Date, BRKS int, BBOH int, DTAB int)
INSERT @ShiftData
VALUES (1, '10/11/2012', 1, 2, 3)
,  (2, '12/11/2013', 3, 4, 5)
,  (3, '10/11/2011', 1, 2, 3)

DECLARE @MapBushingData TABLE (ndx int identity(1,1) not null, LoopCode int, Chopper varchar(10))
INSERT @MapBushingData
VALUES (1, 'Chopper 1')
, (2, 'Chopper 2')
, (3, 'Chopper 3')
Director of Transmogrification Services
Shinobi of Query Language
Master of Yoda Conditional

GeneralRe: Looking for some assistance with a query Pin
MadMyche11-Sep-19 2:56
mveMadMyche11-Sep-19 2:56 
GeneralRe: Looking for some assistance with a query Pin
FrankLepkowski11-Sep-19 5:15
MemberFrankLepkowski11-Sep-19 5:15 

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.