FROM dbo.RJDateLookup
Left JOIN dbo.CST_MS_Quote
ON dbo.RJDateLookup.DateFull = dbo.CST_MS_Quote.QuoteDate
and dbo.CST_MS_Quote.QuoteType = 'C'
and dbo.RJDateLookup.MonthNumber <= month(QuoteDate) + 6
WHERE
dbo.RJDateLookup.DateFull >= '08/01/2012'
AND
Quote = 'AC1586'
All I did was add the quote clause so I could see if it works in one instance.
All it did was return the one record and no dates from the datelookup past August.
I was expecting it to return the quote record and the next 6 months from the datelookup table for a total of 7 records.
Joined: 21 Aug 2012
Location: United States
Online Status: Offline
Posts: 27
Posted: 30 Aug 2012 at 11:40am
Okay some more fuel for the fire. When I try and select dates from the datelookup table alone and filter between 8/1/2012 and 3/1/2013, it returns only the data for August (31 records).
SELECT
*
FROM
RJDateLookup
WHERE
DateFull >= '08/01/2012 00:00:00' AND DateFull < '03/01/2013 00:00:00'
I've also tried DateFull Between '08/01/2012' and '03/01/2013' with the same results.
I did a select * on the table and it came back with all the dates.
Joined: 21 Aug 2012
Location: United States
Online Status: Offline
Posts: 27
Posted: 30 Aug 2012 at 12:24pm
Well it looks like the Datelookup table is missing all dates for Sept. Oct. Nov, Dec, Jan and Feb for each year. Makes no sense. Here is the SQL used to populate the table.
Joined: 21 Aug 2012
Location: United States
Online Status: Offline
Posts: 27
Posted: 30 Aug 2012 at 4:23pm
Okay rebuilt and repopulated the date table and all the dates are in there now. But still no luck in getting all dates to show when linked to the quotes table. GRRRRR.
FROM dbo.RJDateLookup
Left JOIN dbo.CST_MS_Quote
ON dbo.RJDateLookup.DateFull = dbo.CST_MS_Quote.QuoteDate
and dbo.CST_MS_Quote.QuoteType = 'C'
and dbo.RJDateLookup.DateFull <= Dateadd(m,6,CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,QuoteDate))-1),DATEADD(mm,1,QuoteDate)),101))
--AND
--Quote = 'AC1586'
WHERE
dbo.RJDateLookup.DateFull >= '09/01/2012'
Group by
dbo.CST_MS_Quote.MSCo,
dbo.CST_MS_Quote.QuotedBy,
dbo.RJDateLookup.MonthNumber,
dbo.RJDateLookup.MonthName,
--dbo.RJDateLookup.DateFull,
month(dbo.CST_MS_Quote.QuoteDate),
month(dbo.CST_MS_Quote.ReqDate),
dbo.CST_MS_Quote.Location2,
dbo.CST_MS_Quote.MaterialCode,
dbo.CST_MS_Quote.MaterialDescription
order by QuotedBy,Location,MaterialCode
However I'm not sure how to get the extra months as required dates.
both work on the same two fields. So, you need to decide which one you need.
Also, based on whether a join is a left or a right join, they're sensitive to the order of fields in the condition. Whichever of these two conditions you decide to use, I would change them to this:
both work on the same two fields. So, you need to decide which one you need.
Also, based on whether a join is a left or a right join, they're sensitive to the order of fields in the condition. Whichever of these two conditions you decide to use, I would change them to this:
Actually they are not mutually exclusive. one sets the start date and the other sets the end date.
But a new wrinkle has been thrown into the mix last night. They want to be able to group all records that are earlier than the quote date have a status of Active = 'Y' and expired date < current date in the 1st column.
I think I know how to do that using Nested case statements. When I get back to my desk later I'll post the SQL and see whaty happens.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum