Forum Replies Created

Viewing 11 posts - 1 through 11 (of 11 total)

  • RE: Every 3rd Friday of the Month

    yuanyelss (2/18/2011)


    Be careful when you use DW in a datepart function as the number that represents a particular day will change based on the value of @@DATEFIRST...

    In this case, that...

  • RE: Every 3rd Friday of the Month

    I've snipped out both of the additional solutions and will be studying them both. Thank you.

  • RE: Every 3rd Friday of the Month

    This appears to work, at least for 2010 and 2011 (I verified the dates against the calendar). However, it uses a look-up rather than a calculation.

    BEGIN -- Show each...

  • RE: Every 3rd Friday of the Month

    Jeff Moden (2/17/2011)


    SELECT CASE

    WHEN GETDATE() <= CAST(DATEDIFF(dd,-3,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0))/7*7+4+14 AS DATETIME) --3rd Friday Current Month

    ...

  • RE: Every 3rd Friday of the Month

    abair34 (2/17/2011)


    SELECT CASE WHEN current_timestamp > (your 3rd week of month calculation)

    THEN (altered 3rd week of a month calculation based on DATEADD(MONTH, +1, currenttimestamp) instead of current_timestamp

    ELSE (your current 3rd...

  • RE: Every 3rd Friday of the Month

    dosskavi (2/17/2011)


    SELECT

    CONVERT(CHAR(10),

    DATEADD(wk,2,(CURRENT_TIMESTAMP -

    Day(CURRENT_TIMESTAMP)+1)+(6-DATEPART(dw,(CURRENT_TIMESTAMP -

    Day(CURRENT_TIMESTAMP)+1)))),

    121)

    For January 2011, that formula returns the 14th, when the third Friday is on the 21st.

    DECLARE @LoopDate AS DATETIME

    SET @LoopDate = CAST('2011-01-01' AS DATETIME)

    SELECT

    CONVERT(CHAR(10),

    DATEADD(wk,2,(@LoopDate -

    Day(@LoopDate)+1)+(6-DATEPART(dw,(@LoopDate -

    Day(@LoopDate)+1)))),

    121)

    2011-01-14

  • RE: How to replace two values from a single table

    nadarajan_v (2/15/2011)


    Hello Chris_n_Osborne,

    Your assumption is correct and thank you so much for your code snippet. I was able to solve my issue.

    You're welcome. 😀

    nadarajan_v (2/15/2011)


    I agree with you that the...

  • RE: How to replace two values from a single table

    I am working on assumptions about your table designs based on your description.

    Your query is asking for screen names this way:

    U.ScreenName AS OriginalPostBy

    U.ScreenName AS LastPostBy

    Where U = the TBS_UserDetails table.

    If...

  • RE: TSQL Brain Teaser (for me at least)

    Lowell (2/15/2011)


    I Think Mr Celkos post was for a db other than SQL...this is the equivalent:

    Thank you.

  • RE: TSQL Brain Teaser (for me at least)

    CELKO (2/14/2011)


    CREATE TABLE People

    (person_id INTEGER NOT NULL PRIMARY KEY,

    person_name VARCHAR(35) NOT NULL,

    sex_code INTEGER NOT NULL

    CHECK(sex_code IN (1, 2)));

    INSERT INTO People (person_id, person_name, sex_code)

    VALUES (1,...

  • RE: RIGHT OUTER JOIN not returning correct data

    CREATE TABLE GradeLookupTable

    (GradeID INTEGER

    ,GradeLookupName NCHAR(1)

    ,CONSTRAINT pk_Grade PRIMARY KEY (GradeID)

    )

    go

    INSERT INTO GradeLookupTable

    SELECT 1, 'A' UNION

    SELECT 2, 'B'...

Viewing 11 posts - 1 through 11 (of 11 total)