Click here to Skip to main content
15,902,492 members
Home / Discussions / Database
   

Database

 
AnswerRe: mysql + mssql Pin
Pete O'Hanlon16-Apr-07 23:23
mvePete O'Hanlon16-Apr-07 23:23 
GeneralRe: mysql + mssql Pin
tradakad17-Apr-07 1:11
tradakad17-Apr-07 1:11 
GeneralRe: mysql + mssql Pin
Pete O'Hanlon17-Apr-07 1:19
mvePete O'Hanlon17-Apr-07 1:19 
GeneralRe: mysql + mssql Pin
tradakad17-Apr-07 22:50
tradakad17-Apr-07 22:50 
Questiondelete duplicated records Pin
Sophia Rekhi16-Apr-07 22:48
Sophia Rekhi16-Apr-07 22:48 
AnswerRe: delete duplicated records Pin
gauthee16-Apr-07 22:59
gauthee16-Apr-07 22:59 
GeneralRe: delete duplicated records Pin
Sophia Rekhi16-Apr-07 23:31
Sophia Rekhi16-Apr-07 23:31 
GeneralRe: delete duplicated records Pin
gauthee16-Apr-07 23:38
gauthee16-Apr-07 23:38 
Generalclickety Pin
Jerry Hammond17-Apr-07 3:30
Jerry Hammond17-Apr-07 3:30 
QuestionFunction problem Pin
ytubis16-Apr-07 21:26
ytubis16-Apr-07 21:26 
QuestiondataGridView ReadOnly Pin
Ali el16-Apr-07 21:17
Ali el16-Apr-07 21:17 
QuestionWhile Running SQL 2005 Sync Package - i got this message - Sync Failed Pin
Jayaraman B16-Apr-07 20:52
Jayaraman B16-Apr-07 20:52 
Questionchange db from sql server 2000 to sqlserver 2005 Pin
Jes M George16-Apr-07 20:21
Jes M George16-Apr-07 20:21 
AnswerRe: change db from sql server 2000 to sqlserver 2005 Pin
Krish - KP16-Apr-07 20:46
Krish - KP16-Apr-07 20:46 
AnswerRe: change db from sql server 2000 to sqlserver 2005 Pin
Arun.Immanuel20-Apr-07 18:30
Arun.Immanuel20-Apr-07 18:30 
QuestionGet all Sundays between 2 dates in sql Pin
cst_cfit16-Apr-07 19:58
cst_cfit16-Apr-07 19:58 
AnswerRe: Get all Sundays between 2 dates in sql Pin
vivek-g16-Apr-07 20:28
vivek-g16-Apr-07 20:28 
GeneralRe: Get all Sundays between 2 dates in sql Pin
cst_cfit17-Apr-07 23:32
cst_cfit17-Apr-07 23:32 
AnswerRe: Get all Sundays between 2 dates in sql Pin
gauthee16-Apr-07 20:28
gauthee16-Apr-07 20:28 
AnswerRe: Get all Sundays between 2 dates in sql Pin
DQNOK17-Apr-07 4:16
professionalDQNOK17-Apr-07 4:16 
GeneralRe: Get all Sundays between 2 dates in sql Pin
cst_cfit17-Apr-07 23:32
cst_cfit17-Apr-07 23:32 
AnswerRe: Get all Sundays between 2 dates in sql [modified] Pin
DQNOK17-Apr-07 7:58
professionalDQNOK17-Apr-07 7:58 
I re-read your post, and realized I hadn't really answered your question in my first response. You asked how to do it in SQL, and you didn't specify which flavor. I answered in pseudo code; not SQL. Here is another shot at it, this time putting the previous pseudo code into SQL.

I looked thru the (XOpen) SQL standard, and couldn't find the functions I was looking for, so had to settle for generic functions that you will have to substitute for if your system doesn't support them. In both the procedures below I've assumed:
1) the way to get an integer divide is with the '\' operator. This works in Access, but is not universal across DBMs.
2) the whole part of a date interval is actually the number of days between the two dates. The standard does NOT specify this.
3) the existence of a "WEEKDAY" function.
4) that date2 >= date1
5) that you specify a DATE-LITERAL by delimiting it with # signs.

Note that Jan 2, 2000 was a Sunday.

First, a procedure that uses ISO SQL standard CASE notation:

CREATE PROCEDURE numSundays(date1 DATE, date2 DATE) AS
SELECT CINT(date2 - date1) \ 7
+ CASE WEEKDAY(date2) < WEEKDAY(date1)
WHEN TRUE THEN 1 ELSE
CASE WEEKDAY(date2) = WEEKDAY(#JAN-02-2000#)
OR WEEKDAY(date1) = WEEKDAY(#JAN-02-2000#)
WHEN TRUE THEN 1 ELSE 0
END
END
;

And here is the same thing in MS Access notation.

CREATE PROCEDURE numSundays(date1 DATE, date2 DATE) AS
SELECT CINT(date2 - date1) \ 7
+ IIF( WEEKDAY(date2) < WEEKDAY(date1), 1,
IIF( WEEKDAY(date2) = WEEKDAY(#JAN-02-2000#)
OR WEEKDAY(date1) = WEEKDAY(#JAN-02-2000#), 1, 0 ))
;

While more complicated than a looping approach to counting the number of Sundays, they are much more efficient as they are effectively only a simple formula.

Hope this helps


-- modified at 16:35 Tuesday 17th April, 2007
GeneralRe: Get all Sundays between 2 dates in sql Pin
cst_cfit17-Apr-07 23:30
cst_cfit17-Apr-07 23:30 
Questionretrieving the highest IDENTITY number in a table:sqlserv05? Pin
giddy_guitarist16-Apr-07 10:21
giddy_guitarist16-Apr-07 10:21 
AnswerRe: retrieving the highest IDENTITY number in a table:sqlserv05? Pin
Mark J. Miller16-Apr-07 12:20
Mark J. Miller16-Apr-07 12:20 

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.