1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
SET DATEFIRST 6
GO
CREATE TABLE #TEST (dates datetime)
INSERT INTO #TEST (dates) VALUES ('20081226')
INSERT INTO #TEST (dates) VALUES ('20081227')
INSERT INTO #TEST (dates) VALUES ('20081228')
INSERT INTO #TEST (dates) VALUES ('20081229')
INSERT INTO #TEST (dates) VALUES ('20081230')
INSERT INTO #TEST (dates) VALUES ('20081231')
INSERT INTO #TEST (dates) VALUES ('20090101')
INSERT INTO #TEST (dates) VALUES ('20090102')
INSERT INTO #TEST (dates) VALUES ('20090103')
INSERT INTO #TEST (dates) VALUES ('20090104')
INSERT INTO #TEST (dates) VALUES ('20090105')
SELECT CONVERT(CHAR,dates,112) AS dates
INTO #test2
FROM #test
SELECT dates, DATEPART(WEEK,dates) AS numsem
INTO #test3
FROM #test2
UPDATE #test3 SET numsem = 1 WHERE numsem = 53
SELECT min(dates) as dates
INTO #test4
FROM #test3
WHERE numsem = 1 |
Partager