May 19, 2015 at 3:40 pm
eirk tsomik (5/19/2015)
Here is the sample datasessionKeylocationKeysessionStartsessionEndinstructorKeyFlagcarKeyproductTypeKey
164192NULL2015-07-01 06:00:00.0002015-07-01 08:00:00.00036754NULL1332
164196342015-07-01 09:45:00.0002015-07-01 11:45:00.00013783NULL1332
164195342015-07-01 11:45:00.0002015-07-01 13:45:00.00013783NULL1332
164085132015-07-01 14:00:00.0002015-07-01 16:00:00.00039097NULL1332
164096132015-07-01 16:15:00.0002015-07-01 18:15:00.00039097NULL1332
164133132015-07-01 18:15:00.0002015-07-01 20:15:00.00039097NULL1332
What is the structure of the table? How do I cut/paste/insert this data?
Have you even bothered to read that article I pointed you to?
May 19, 2015 at 3:44 pm
you can just use this pseudo code
DECLARE @Results TABLE (
sessionKey int NOT NULL,
locationKey smallint,
sessionStart datetime NOT NULL,
sessionEnd datetime NOT NULL,
instructorKey int NOT NULL,
Flag int,
carKey smallint NOT NULL,
productTypeKey smallint NOT NULL )
INSERT INTO @Results
SELECT 164192, NULL, '2015-07-01 06:00:00', '2015-07-01 08:00:00', 36754, NULL, 133, 2 UNION ALL
SELECT 164193, 34, '2015-07-01 08:00:00', '2015-07-01 10:00:00', 36754, NULL, 133, 2 UNION ALL
--SELECT 164196, 34, '2015-07-01 09:45:00', '2015-07-01 11:45:00', 13783, NULL, 133, 2 UNION ALL
SELECT 164195, 34, '2015-07-01 11:45:00', '2015-07-01 13:45:00', 13783, NULL, 133, 2 UNION ALL
SELECT 164085, 13, '2015-07-01 14:00:00', '2015-07-01 16:00:00', 39097, NULL, 133, 2 UNION ALL
SELECT 164096, 13, '2015-07-01 16:15:00', '2015-07-01 18:15:00', 39097, NULL, 133, 2 UNION ALL
SELECT 164133, 13, '2015-07-01 18:15:00', '2015-07-01 20:15:00', 39097, NULL, 133, 2
SELECT a.sessionKey,
a.locationKey,
a.instructorKey,
a.sessionStart,
a.sessionEnd,
b.sessionStart AS NextStart,
b.sessionEnd AS NextEnd,
b.instructorKey AS NextInstr
FROM @Results a
JOIN @Results b
ON (b.instructorKey = a.instructorKey OR b.carKey = a.carKey)
AND b.sessionStart BETWEEN DATEADD(n, -29, a.sessionEnd) AND DATEADD(n, 29, a.sessionEnd)
WHERE a.sessionStart = '2015-07-01 11:45:00'
Web programmer
May 19, 2015 at 3:47 pm
DECLARE @Results TABLE (
sessionKey int NOT NULL,
locationKey smallint,
sessionStart datetime NOT NULL,
sessionEnd datetime NOT NULL,
instructorKey int NOT NULL,
Flag int,
carKey smallint NOT NULL,
productTypeKey smallint NOT NULL )
INSERT INTO @Results
SELECT 164192, NULL, '2015-07-01 06:00:00', '2015-07-01 08:00:00', 36754, NULL, 133, 2 UNION ALL
SELECT 164193, 34, '2015-07-01 08:00:00', '2015-07-01 10:00:00', 36754, NULL, 133, 2 UNION ALL
--SELECT 164196, 34, '2015-07-01 09:45:00', '2015-07-01 11:45:00', 13783, NULL, 133, 2 UNION ALL
SELECT 164195, 34, '2015-07-01 11:45:00', '2015-07-01 13:45:00', 13783, NULL, 133, 2 UNION ALL
SELECT 164085, 13, '2015-07-01 14:00:00', '2015-07-01 16:00:00', 39097, NULL, 133, 2 UNION ALL
SELECT 164096, 13, '2015-07-01 16:15:00', '2015-07-01 18:15:00', 39097, NULL, 133, 2 UNION ALL
SELECT 164133, 13, '2015-07-01 18:15:00', '2015-07-01 20:15:00', 39097, NULL, 133, 2
SELECT a.sessionKey,
a.locationKey,
a.instructorKey,
a.sessionStart,
a.sessionEnd,
b.sessionStart AS NextStart,
b.sessionEnd AS NextEnd,
b.instructorKey AS NextInstr
FROM @Results a
JOIN @Results b
ON (b.instructorKey = a.instructorKey OR b.carKey = a.carKey)
AND b.sessionStart BETWEEN DATEADD(n, -29, a.sessionEnd) AND DATEADD(n, 29, a.sessionEnd)
WHERE a.sessionStart = '2015-07-01 11:45:00'
Web programmer
May 19, 2015 at 3:48 pm
you can just use pseudo code
DECLARE @Results TABLE (
sessionKey int NOT NULL,
locationKey smallint,
sessionStart datetime NOT NULL,
sessionEnd datetime NOT NULL,
instructorKey int NOT NULL,
Flag int,
carKey smallint NOT NULL,
productTypeKey smallint NOT NULL )
INSERT INTO @Results
SELECT 164192, NULL, '2015-07-01 06:00:00', '2015-07-01 08:00:00', 36754, NULL, 133, 2 UNION ALL
SELECT 164193, 34, '2015-07-01 08:00:00', '2015-07-01 10:00:00', 36754, NULL, 133, 2 UNION ALL
--SELECT 164196, 34, '2015-07-01 09:45:00', '2015-07-01 11:45:00', 13783, NULL, 133, 2 UNION ALL
SELECT 164195, 34, '2015-07-01 11:45:00', '2015-07-01 13:45:00', 13783, NULL, 133, 2 UNION ALL
SELECT 164085, 13, '2015-07-01 14:00:00', '2015-07-01 16:00:00', 39097, NULL, 133, 2 UNION ALL
SELECT 164096, 13, '2015-07-01 16:15:00', '2015-07-01 18:15:00', 39097, NULL, 133, 2 UNION ALL
SELECT 164133, 13, '2015-07-01 18:15:00', '2015-07-01 20:15:00', 39097, NULL, 133, 2
SELECT a.sessionKey,
a.locationKey,
a.instructorKey,
a.sessionStart,
a.sessionEnd,
b.sessionStart AS NextStart,
b.sessionEnd AS NextEnd,
b.instructorKey AS NextInstr
FROM @Results a
JOIN @Results b
ON (b.instructorKey = a.instructorKey OR b.carKey = a.carKey)
AND b.sessionStart BETWEEN DATEADD(n, -29, a.sessionEnd) AND DATEADD(n, 29, a.sessionEnd)
WHERE a.sessionStart = '2015-07-01 11:45:00'
Web programmer
May 19, 2015 at 4:12 pm
May 19, 2015 at 4:50 pm
@eirk tsomik,
I'm not sure why but it looks like 3 posts where you posted some readily consumable code were deleted by that autospam detector or an over-zealous monitor. Did you want me to undelete one of them for you?
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 16 through 20 (of 20 total)
You must be logged in to reply to this topic. Login to reply