Click here to Skip to main content
15,895,656 members
Home / Discussions / Database
   

Database

 
GeneralRe: How to define a null-ignoring unique constraint Pin
supercali12-Sep-06 4:16
supercali12-Sep-06 4:16 
QuestionFinding recurring dates. Pin
T-Smooth11-Sep-06 3:06
T-Smooth11-Sep-06 3:06 
AnswerRe: Finding recurring dates. Pin
Eric Dahlvang11-Sep-06 3:50
Eric Dahlvang11-Sep-06 3:50 
GeneralRe: Finding recurring dates. Pin
T-Smooth11-Sep-06 5:48
T-Smooth11-Sep-06 5:48 
AnswerRe: Finding recurring dates. Pin
Eric Dahlvang11-Sep-06 6:42
Eric Dahlvang11-Sep-06 6:42 
GeneralRe: Finding recurring dates. Pin
T-Smooth11-Sep-06 8:24
T-Smooth11-Sep-06 8:24 
GeneralRe: Finding recurring dates. Pin
Eric Dahlvang11-Sep-06 10:19
Eric Dahlvang11-Sep-06 10:19 
AnswerRe: Finding recurring dates. Pin
Michael Potter11-Sep-06 10:20
Michael Potter11-Sep-06 10:20 
Not sure why you would want to set up a table containing each date when the calculations are just as easy to write.

Have you considered adding a few more fields to your table:
1) DayNameIndexForMonth (i.e. 1st Sunday, 2nd Sunday, 3rd Sunday)
2) DayOfYear (i.e. This is the 74th day of the year)
3) Quarter (i.e. This day is in the 3rd Quarter)

This might make your queries a lot easier.

On the other hand, you can always calculate on the fly. With only 365 iterations per year, loops should execute quickly enough. Knowing that the 3rd 'Day Name' of every month will fall between the 15th and 21st day you can code it like this:

CREATE PROCEDURE RecurringDates_ThirdSunday
(
    @Start DATETIME,
    @End DATETIME
)
AS
    DECLARE @curDt DATETIME
    SET @curDt = @Start
    
    DECLARE @t TABLE (GoodDate DATETIME NOT NULL)
    
    WHILE @curDt <= @End
    BEGIN
        IF DATEPART(dw,@curDt) = 1
        BEGIN 
            IF DATEPART(dd,@curDt) BETWEEN 15 AND 21
                BEGIN
                    INSERT INTO @t (GoodDate) VALUES (@curDt)
                END
        END
    
        SET @curDt = DATEADD(dd,1,@CurDt)
    END
    
    SELECT *
    FROM @t

GeneralRe: Finding recurring dates. Pin
Eric Dahlvang11-Sep-06 10:55
Eric Dahlvang11-Sep-06 10:55 
QuestionCondition as parameter of sp ... ? [modified] Pin
devboycpp10-Sep-06 23:22
devboycpp10-Sep-06 23:22 
AnswerRe: Condition as parameter of sp ... ? Pin
_AK_10-Sep-06 23:29
_AK_10-Sep-06 23:29 
GeneralRe: Condition as parameter of sp ... ? [modified] Pin
devboycpp10-Sep-06 23:38
devboycpp10-Sep-06 23:38 
GeneralRe: Condition as parameter of sp ... ? Pin
_AK_10-Sep-06 23:55
_AK_10-Sep-06 23:55 
GeneralRe: Condition as parameter of sp ... ? Pin
devboycpp11-Sep-06 0:24
devboycpp11-Sep-06 0:24 
GeneralRe: Condition as parameter of sp ... ? Pin
_AK_11-Sep-06 0:33
_AK_11-Sep-06 0:33 
AnswerRe: Condition as parameter of sp ... ? Pin
Eric Dahlvang11-Sep-06 3:08
Eric Dahlvang11-Sep-06 3:08 
QuestionNavigation buttons Pin
Ranjita Ghosh10-Sep-06 21:41
Ranjita Ghosh10-Sep-06 21:41 
AnswerRe: Navigation buttons Pin
Tushar Kothari11-Sep-06 1:06
Tushar Kothari11-Sep-06 1:06 
GeneralRe: Navigation buttons Pin
Ranjita Ghosh11-Sep-06 1:48
Ranjita Ghosh11-Sep-06 1:48 
QuestionCatching errors raised by SP Pin
Uma Kameswari10-Sep-06 21:40
Uma Kameswari10-Sep-06 21:40 
AnswerRe: Catching errors raised by SP Pin
Tushar Kothari11-Sep-06 1:10
Tushar Kothari11-Sep-06 1:10 
GeneralRe: Catching errors raised by SP Pin
Amit Kumar G12-Sep-06 16:28
Amit Kumar G12-Sep-06 16:28 
QuestionCannot edit the existing record Pin
Ranjita Ghosh10-Sep-06 21:09
Ranjita Ghosh10-Sep-06 21:09 
AnswerRe: Cannot edit the existing record Pin
Tushar Kothari11-Sep-06 1:13
Tushar Kothari11-Sep-06 1:13 
GeneralRe: Cannot edit the existing record Pin
Ranjita Ghosh11-Sep-06 1:36
Ranjita Ghosh11-Sep-06 1:36 

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.