Click here to Skip to main content
15,886,664 members
Home / Discussions / Database
   

Database

 
GeneralRe: tsql query puzzle Pin
andyharman4-Aug-04 23:47
professionalandyharman4-Aug-04 23:47 
GeneralData Dictionary Pin
Britnt72-Aug-04 3:08
Britnt72-Aug-04 3:08 
Generallooping datatable Pin
robmays1-Aug-04 23:23
robmays1-Aug-04 23:23 
GeneralRe: looping datatable Pin
Steven Campbell2-Aug-04 14:32
Steven Campbell2-Aug-04 14:32 
GeneralRe: looping datatable Pin
robmays2-Aug-04 20:56
robmays2-Aug-04 20:56 
GeneralCollation name question... Pin
theJazzyBrain1-Aug-04 6:54
theJazzyBrain1-Aug-04 6:54 
GeneralRe: Collation name question... Pin
Thea Burger2-Aug-04 1:11
Thea Burger2-Aug-04 1:11 
QuestionDetecting overlapping date ranges - best strategy - help? Pin
Paul Evans1-Aug-04 5:38
Paul Evans1-Aug-04 5:38 
Hi there,
I have a situation where a user may want to search against stored date ranges and single dates... while using either a single date or a date range. A document has content values associated with it.

The data is stored within a Postgresql database (although this is more a strategic thing so for the purpose of this discussion that doesn't really matter) and used by a c# application. In
the content table amongst other things it includes 2 date fields - a start date field (that doubles as the single date storage) and an end date field.

ORs are very hard for databases to do on large tables, so I am trying my best to avoid using an OR - instead joining the same table multiple times and using AND. Of course multiple joins are pretty hard for it too - just doesn't seem to be as hard.

I'm also trying to avoid using temporary tables where possible.

Searching for a single date within a range is pretty easy without resorting to either OR or temporary tables.

Note below isn't the actual code, just a simplified mockup.

Searching a single date against a stored range goes something like: (1990-01-01 being the search term)

select docid from document d, contentvalue v1 where
docid.cvid = v1.cvid AND
v1.type = 'daterange' AND
v1.startdate >= '1990-01-01' AND
v1.enddate <= '1990-01-01';


... a range against a single date goes ...
(1990-01-01 - 2000-01-01 being search term)
select docid from document d, contentvalue v1 , contentvalue v2
where
docid.cvid = v1.cvid AND
v1.type = 'date' AND
v1.startdate >= '1990-01-01'
v1.cvid = v2.cvid AND
v2.type = 'date' AND
v2.startdate <= '2000-01-01';



Right now though I'm stuck trying to figure out a decent way of comparing 2 overlapping ranges without using temporary tables or an OR.

If anyone has any alternate strategies for the whole thing, or for decent date-range against date-range storage within a database, and / or any links to any resources on the web I'd be very thankful.

/**********************************
Paul Evans, Dorset, UK.
**********************************/
Generalhai Pin
Asha Rams31-Jul-04 22:32
Asha Rams31-Jul-04 22:32 
GeneralBTrieve 6.15 Pin
Mega131-Jul-04 18:05
Mega131-Jul-04 18:05 
GeneralRe: BTrieve 6.15 Pin
Mekong River1-Aug-04 4:07
Mekong River1-Aug-04 4:07 
GeneralSynchronizing tables Pin
winpiglet31-Jul-04 10:43
winpiglet31-Jul-04 10:43 
Questionis there any Win32 function help access SQL server? Pin
fu031-Jul-04 1:47
fu031-Jul-04 1:47 
AnswerRe: is there any Win32 function help access SQL server? Pin
Michael P Butler31-Jul-04 22:14
Michael P Butler31-Jul-04 22:14 
GeneralSP - Efficient &quot;Find&quot; method Pin
UB30-Jul-04 21:58
UB30-Jul-04 21:58 
GeneralRe: SP - Efficient "Find" method Pin
Daniel Turini31-Jul-04 11:05
Daniel Turini31-Jul-04 11:05 
GeneralSQL query to generate random numbers Pin
Imtiaz Murtaza29-Jul-04 23:45
Imtiaz Murtaza29-Jul-04 23:45 
GeneralRe: SQL query to generate random numbers Pin
Steven Campbell30-Jul-04 7:55
Steven Campbell30-Jul-04 7:55 
GeneralRe: SQL query to generate random numbers Pin
Grimolfr30-Jul-04 8:22
Grimolfr30-Jul-04 8:22 
GeneralBeginner - OLE DB - bind IRowSet to grid control Pin
poptcat29-Jul-04 21:46
poptcat29-Jul-04 21:46 
GeneralRelation between tables Pin
RoyRose7829-Jul-04 20:17
RoyRose7829-Jul-04 20:17 
GeneralRelation between tables Pin
Sendilkumar.M30-Jul-04 19:13
Sendilkumar.M30-Jul-04 19:13 
GeneralRe: Relation between tables Pin
RoyRose7830-Jul-04 22:15
RoyRose7830-Jul-04 22:15 
GeneralPlease recommend on connection to Ms Acess Database Pin
DotNet29-Jul-04 15:16
DotNet29-Jul-04 15:16 
GeneralRe: Please recommend on connection to Ms Acess Database Pin
EdbertP29-Jul-04 16:52
EdbertP29-Jul-04 16:52 

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.