Viewing 11 posts - 1 through 11 (of 11 total)
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...
February 18, 2011 at 10:03 pm
I've snipped out both of the additional solutions and will be studying them both. Thank you.
February 18, 2011 at 3:11 pm
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...
February 17, 2011 at 9:18 pm
Jeff Moden (2/17/2011)
SELECT CASEWHEN GETDATE() <= CAST(DATEDIFF(dd,-3,DATEADD(mm,DATEDIFF(mm,0,GETDATE()),0))/7*7+4+14 AS DATETIME) --3rd Friday Current Month
...
February 17, 2011 at 8:51 pm
abair34 (2/17/2011)
THEN (altered 3rd week of a month calculation based on DATEADD(MONTH, +1, currenttimestamp) instead of current_timestamp
ELSE (your current 3rd...
February 17, 2011 at 4:42 pm
dosskavi (2/17/2011)
SELECTCONVERT(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
February 17, 2011 at 2:01 pm
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)
February 15, 2011 at 7:14 pm
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...
February 15, 2011 at 5:26 pm
Lowell (2/15/2011)
I Think Mr Celkos post was for a db other than SQL...this is the equivalent:
Thank you.
February 15, 2011 at 7:56 am
CELKO (2/14/2011)
(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,...
February 15, 2011 at 6:53 am
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'...
February 8, 2011 at 7:36 pm
Viewing 11 posts - 1 through 11 (of 11 total)