Click here to Skip to main content
15,897,718 members
Home / Discussions / Database
   

Database

 
AnswerRe: Accounting problem in SQL Pin
CHill6019-May-21 2:55
mveCHill6019-May-21 2:55 
QuestionSQL Server Execution Timeout Expired Pin
idkd12-May-21 23:00
idkd12-May-21 23:00 
AnswerRe: SQL Server Execution Timeout Expired Pin
SeanChupas13-May-21 1:49
SeanChupas13-May-21 1:49 
QuestionIn-memory database with acid transactions and high availability Pin
Mathieu Seillier12-May-21 2:54
Mathieu Seillier12-May-21 2:54 
AnswerRe: In-memory database with acid transactions and high availability Pin
Mycroft Holmes12-May-21 13:00
professionalMycroft Holmes12-May-21 13:00 
AnswerRe: In-memory database with acid transactions and high availability Pin
Richard MacCutchan12-May-21 21:08
mveRichard MacCutchan12-May-21 21:08 
AnswerRe: In-memory database with acid transactions and high availability Pin
Meysam Toluie28-Jan-22 23:06
Meysam Toluie28-Jan-22 23:06 
GeneralRe: In-memory database with acid transactions and high availability Pin
OriginalGriff28-Jan-22 23:08
mveOriginalGriff28-Jan-22 23:08 
GeneralRe: In-memory database with acid transactions and high availability Pin
Meysam Toluie28-Jan-22 23:25
Meysam Toluie28-Jan-22 23:25 
QuestionSQL Server round trip issue between server and client pc Pin
Mou_kol1-May-21 6:35
Mou_kol1-May-21 6:35 
AnswerRe: SQL Server round trip issue between server and client pc Pin
Mycroft Holmes1-May-21 11:57
professionalMycroft Holmes1-May-21 11:57 
AnswerRe: SQL Server round trip issue between server and client pc Pin
Gerry Schmitz1-May-21 17:12
mveGerry Schmitz1-May-21 17:12 
GeneralRe: SQL Server round trip issue between server and client pc Pin
Mycroft Holmes2-May-21 12:24
professionalMycroft Holmes2-May-21 12:24 
GeneralRe: SQL Server round trip issue between server and client pc Pin
Gerry Schmitz2-May-21 18:53
mveGerry Schmitz2-May-21 18:53 
QuestionSqlServer (and ADO.NET) mystery... Pin
Super Lloyd27-Apr-21 19:19
Super Lloyd27-Apr-21 19:19 
AnswerRe: SqlServer (and ADO.NET) mystery... Pin
Richard Deeming27-Apr-21 22:11
mveRichard Deeming27-Apr-21 22:11 
GeneralRe: SqlServer (and ADO.NET) mystery... Pin
Super Lloyd27-Apr-21 22:42
Super Lloyd27-Apr-21 22:42 
AnswerRe: SqlServer (and ADO.NET) mystery... Pin
Mycroft Holmes28-Apr-21 11:46
professionalMycroft Holmes28-Apr-21 11:46 
QuestionInterval schedule Pin
Member 1462398929-Apr-21 2:56
Member 1462398929-Apr-21 2:56 
AnswerRe: Interval schedule Pin
Victor Nijegorodov27-Apr-21 20:45
Victor Nijegorodov27-Apr-21 20:45 
AnswerRe: Interval schedule Pin
Richard Deeming27-Apr-21 22:08
mveRichard Deeming27-Apr-21 22:08 
GeneralRe: Interval schedule Pin
Member 1462398929-Apr-21 2:38
Member 1462398929-Apr-21 2:38 
This is EXACTLY what I needed. This was far too complex for me to comprehend, so I started to look into why it works and breaking down everything in piece. No comments in anything for the query below, but should be able to figure it out for someone looking at the same thing:

SQL
SELECT 
	DATEDIFF(HOUR, '1:00', '23:00')

SELECT 
	DATEDIFF(HOUR, '1:00', '23:00') / 4

SELECT 
	(1 + DATEDIFF(HOUR, '1:00', '23:00')) / 4

SELECT
	ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS N  
FROM 
	sys.all_columns

SELECT TOP ((1 + DateDiff(hour, '1:00', '23:00')) / 4) 
    ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) As N 
FROM 
    sys.all_columns

SELECT 
	DATEADD(HOUR, 5 * 4, '1:00') As ScheduleTime
UNION
SELECT 
	DATEADD(HOUR, 4 * 4, '1:00') As ScheduleTime
UNION
SELECT 
	DATEADD(HOUR, 3 * 4, '1:00') As ScheduleTime
UNION
SELECT 
	DATEADD(HOUR, 2 * 4, '1:00') As ScheduleTime
UNION
SELECT 
	DATEADD(HOUR, 1 * 4, '1:00') As ScheduleTime

SELECT
    ',' + CAST(T.ScheduleTime As char(5))
FROM
    /* Tally table: */
    (
        SELECT TOP ((1 + DateDiff(hour, '1:00', '23:00')) / 4) 
            ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) As n
        FROM 
            sys.all_columns
    ) As N
    /* Generated schedule: */
    CROSS APPLY 
    (
        SELECT DateAdd(hour, N.n * 4, '1:00') As ScheduleTime
    ) As T
FOR XML PATH('')


I had to make an adjustment to the final query though to make sure I was getting a schedule for a 24 hour period instead from the start time to midnight:
SQL
WITH cteSource As
(
	SELECT CAST('13:00' As time) As StartTime, 4 As Hours
	UNION SELECT CAST('01:00' As time) As StartTime, 7 As Hours
)
SELECT
    StartTime,
    Hours
    ,STUFF(T.ScheduleTime, 1, 1, '') As ScheduleTime
FROM
    cteSource As S
    CROSS APPLY
    (
        SELECT
			
            ',' + CAST(T.ScheduleTime As char(5))
        FROM
            /* Tally table: */
            (

                SELECT TOP (24 / S.Hours) 
                    ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) As n
                FROM 
                    sys.all_columns
			
            ) As N
            /* Generated schedule: */
            CROSS APPLY 
            (
                
				SELECT DateAdd(hour, N.n * S.Hours, S.StartTime) As ScheduleTime

            ) As T
        FOR XML PATH('')
    ) As T (ScheduleTime)


modified 29-Apr-21 15:03pm.

QuestionRetail inventory management DB Design Pin
vineet123456712-Apr-21 23:42
vineet123456712-Apr-21 23:42 
AnswerRe: Retail inventory management DB Design Pin
Victor Nijegorodov13-Apr-21 0:54
Victor Nijegorodov13-Apr-21 0:54 
AnswerRe: Retail inventory management DB Design Pin
RedDk13-Apr-21 12:10
RedDk13-Apr-21 12:10 

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.