Viewing 15 posts - 46 through 60 (of 2,169 total)
Are you referring to this function?
https://www.sqltopia.com/algorithms/date-and-time/get-the-nth-weekday-of-any-interval/
I can't see that it should take 4 seconds to run over a million date interval?
December 1, 2020 at 6:42 pm
As Jeff states, there are so many things that prevent you from doing a simple ALTER TABLE ALTER COLUMN.
I have recently put my sp_AlterColumn on GitHub. I have used...
November 20, 2020 at 8:35 pm
My goal was to demonstrate you don't need two cross apply.
SELECT SUBSTRING(CONVERT(CHAR(9), DATEADD(MONTH, DATEDIFF(MONTH, 0, t.thedate), 0), 6),...
November 16, 2020 at 1:57 pm
WITH cteDates(this, limit)
AS (
SELECT MIN(Startdate),
...
November 16, 2020 at 9:23 am
I use Google...
https://weblogs.sqlteam.com/peterl/2009/07/12/how-to-calculate-the-number-of-weekdays-for-any-given/
October 17, 2020 at 6:47 pm
-- swePeso
SELECTAccountNumber,
STRING_AGG(Value, ',') WITHIN GROUP (ORDER BY Value)
FROM#TestData
GROUP BYAccountNumber;
April 5, 2019 at 9:13 am
Be very careful with LAG here. If you for some reason don't have data for the previous measure period, you will get the measure period before that.
That's why why need...
March 1, 2015 at 2:44 am
-- SwePeso
WITH cteData
AS (
SELECTDESPATCH_ID,
SAMPLE_ID,
SUBSTRING(SAMPLE_ID, PATINDEX('%[0-9]%', SAMPLE_ID), LEN(SAMPLE_ID)) - ROW_NUMBER() OVER (PARTITION BY DESPATCH_ID ORDER BY SAMPLE_ID) AS grp
FROMdbo.SAMPLE_TABLE
)
SELECTDESPATCH_ID,
MIN(SAMPLE_ID) AS FromID,
MAX(SAMPLE_ID) AS ToID
FROMcteData
GROUP BYDESPATCH_ID,
grp
ORDER BYDESPATCH_ID,
grp;
March 1, 2015 at 2:34 am
-- SwePeso - Preaggregation/filtering step
SELECTSetID,
COUNT(*) AS cnt,
MIN(ItemCode) AS mn,
MAX(ItemCode) AS mx,
CHECKSUM_AGG(CHECKSUM(ItemCode)) AS chk
INTO#Temp
FROMdbo.SetsItems WITH (NOLOCK)
GROUP BYSetID;
-- SwePeso - projection step
SELECTROW_NUMBER() OVER (ORDER BY w.chk) AS UniqueSetID,
STUFF(f.Data, 1, 2, N'') AS...
March 1, 2015 at 2:27 am
This is a simple case of Relational Division, of which I am particular fond of.
The result isSetIDSetID
110
211
78
79
89By using this piece of codeSELECTkc.SetID,
nc.SetID
FROM(
SELECTSetID,
COUNT(*) AS cnt
FROMdbo.SetsItems
GROUP BYSetID
) AS kc
INNER JOIN(
SELECTSetID,
COUNT(*) AS cnt
FROMdbo.SetsItems
GROUP...
March 1, 2015 at 2:18 am
Thank you for taking the time (pun intended) to test the different solutions.
August 13, 2014 at 6:37 am
DECLARE@Sample TABLE
(
s1 DATETIME,
f1 DATETIME,
s2 DATETIME,
f2 DATETIME
);
INSERT@Sample
(
s1,
f1,
s2,
f2
)
VALUES('2014-08-13 07:00', '2014-08-13 12:00', '2014-08-13 10:00', '2014-08-13 19:00'),
('2014-08-13 07:00', '2014-08-13 12:00', '2014-08-13 09:00', '2014-08-13 10:00'),
('2014-08-13 07:00', '2014-08-13 12:00', '2014-08-13 13:00', '2014-08-13 19:00');
-- SwePeso
SELECTs.*,
x.*
FROM@Sample AS s
CROSS...
August 13, 2014 at 5:28 am
Did you wrap the code as an inline table-valued function?
CREATE FUNCTION dbo.OverlapHours
(
@s1 DATETIME,
@f1 DATETIME,
@s2 DATETIME,
@f2 DATETIME
)
RETURNS TABLE
AS
RETURN(
SELECTCASE
WHEN MAX(FromTime) < MIN(ToTime) THEN DATEDIFF(HOUR, MAX(FromTime), MIN(ToTime))
ELSE 0
END AS [Hours]
FROM(
VALUES(@s1, @f1),
(@s2, @f2)
) AS...
August 13, 2014 at 5:09 am
Viewing 15 posts - 46 through 60 (of 2,169 total)