Viewing 15 posts - 76 through 90 (of 623 total)
Got it but still returning incorrect data, lag value for ID2 on 2022-07-04 should be 200
--Microsoft SQL Server 2019
--Build a temp calendar table
DROP TABLE IF EXISTS...
August 5, 2022 at 8:38 pm
[/quote]Why can't you use CTEs?[/quote]
I want to compile a view into a third party system that does not support CTEs. If it's not possible to accomplish without CTEs I may...
August 5, 2022 at 8:27 pm
If you add the LAG columns to #MyData you could try CROSS JOIN'ing the calendar rows with the distinct IDs. Then LEFT JOIN #MyData on id and date.
I can't...
August 5, 2022 at 7:25 pm
Hello Again,
I have added to my DML setup to more accurately reflect my situation.
Added a second calendar type but that doesn't see to be an issue.
Added an ID to my...
August 5, 2022 at 6:01 pm
I am still studying the code. I anticipate I am going to have an additional requirement.
I want to report on 2022-07-10. There is no data on 2022-07-10 so I get...
August 4, 2022 at 10:37 pm
Looks like I can wrap around the code as a subquery and apply the criteria to the outer query
--Microsoft SQL Server 2019
--Build a temp calendar table
DROP...
August 4, 2022 at 10:28 pm
I guess the method needs the previous date to be returned. Whenever I add a criteria for a specific date I don't get the previous data.
SELECT C.CalendarDate
...
August 4, 2022 at 7:48 pm
Okay, maybe I'm a bit daft, but couldn't you simply use this:
CREATE OR ALTER VIEW Test
AS
SELECT *
FROM Calendar C
LEFT JOIN Events E ON C.CalendarDate BETWEEN...
July 15, 2022 at 9:45 pm
I think the below does it. Any comments about performance best practices for doing this sort of thing would be welcome.
CREATE OR ALTER VIEW Test
AS
SELECT * FROM Calendar C
CROSS APPLY
(
SELECT...
July 15, 2022 at 7:40 pm
Event 1 ended on 2022-02-01 so it shouldn't be included when querying the view for @StartDate = '2022-07-01' and @EndDate = '2022-07-31'
July 15, 2022 at 7:16 pm
This query returns no rows
with
gaps_cte(CalDate, [DayName] ,BusinessDay, Multiplier, Comment, gap) as (
select *, case when BusinessDay<>lag(BusinessDay) over (order by CalDate) then...
June 30, 2022 at 6:25 pm
I'm really curious about this request. What is the intended use of the computed "Multiplier" column?
If the answer is to determine which day is (for example) "3 business days...
June 30, 2022 at 6:15 pm
I guess this works but its not particularly pleasing to me.
SELECT
*
FROM
(
SELECT
*
FROM
(
SELECT
*,RANK() OVER (PARTITION BY MyIdentifier ORDER BY LoadDateTime DESC) LoadDateTimeRank
FROM #temptable
) T1
WHERE
LoadDateTimeRank...
September 27, 2021 at 5:45 pm
That works with my sample data but if there are more than 2 records prior to the date range I don't think it will work. See below with additional sample...
September 27, 2021 at 5:35 pm
Very nice, thank you. Putting aside the most recent non-null record issue I started toying with the below. The advantage being that I don't have too have a second expanded...
July 26, 2018 at 4:20 pm
Viewing 15 posts - 76 through 90 (of 623 total)