Author |
Topic |
dt293
Starting Member
8 Posts |
Posted - 2007-06-22 : 10:05:13
|
Hello all,I am trying to write a stored procedure that will return data based on the creation date. Basically the first table (Register) contains two fields called From Entry No and To Entry No. EgCreation Date2007-06-22From Entry No655530To Entry No655537The second table (Entry) has each individual line entry for these Entry No's. EgEntry No655530655531655532655533655534655535655536655537How would I join these to tables to return each line from the Entry table based on a date?Any help would be greatly appreciated. |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-22 : 10:07:07
|
creation date is in which table ? KH[spoiler]Time is always against us[/spoiler] |
|
|
dt293
Starting Member
8 Posts |
Posted - 2007-06-22 : 10:18:48
|
Register table contains;Creation DateFrom Entry NoTo Entry NoEntry table contains;Entry No (Which is each individual line item)Thanks |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-22 : 10:24:41
|
[code]DECLARE @Register TABLE( Creation_Date datetime, From_Entry_No int, To_Entry_No int)INSERT INTO @RegisterSELECT '2007-06-22', 655530, 655537DECLARE @Entry TABLE( Entry_No int)INSERT INTO @EntrySELECT 655530 UNION ALLSELECT 655531 UNION ALLSELECT 655532 UNION ALLSELECT 655533 UNION ALLSELECT 655534 UNION ALLSELECT 655535 UNION ALLSELECT 655536 UNION ALLSELECT 655537SELECT *FROM @Register r INNER JOIN @Entry e ON r.From_Entry_No <= e.Entry_No AND r.To_Entry_No >= e.Entry_NoWHERE r.Creation_Date = '2007-06-22'[/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
dt293
Starting Member
8 Posts |
Posted - 2007-06-22 : 10:40:18
|
OK, but I need to get back all entries from a particular day rather than specifying the entry no's.Here is some dataRegister tableFrom Entry No To Entry No Creation Date Column1 Column23466557 3466558 2007-06-22 00:00:00.000 PURCHASES ITAHIREntry tableEntry No Column13466557 ******3466558 Hope this make a bit more sense. |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-22 : 10:43:00
|
quote: Originally posted by dt293 OK, but I need to get back all entries from a particular day rather than specifying the entry no's.Here is some dataRegister tableFrom Entry No To Entry No Creation Date Column1 Column23466557 3466558 2007-06-22 00:00:00.000 PURCHASES ITAHIREntry tableEntry No Column13466557 ******3466558 Hope this make a bit more sense.
The query did just what you wanted by specifying the date in redSELECT *FROM @Register r INNER JOIN @Entry e ON r.From_Entry_No <= e.Entry_No AND r.To_Entry_No >= e.Entry_NoWHERE r.Creation_Date = '2007-06-22' KH[spoiler]Time is always against us[/spoiler] |
|
|
dt293
Starting Member
8 Posts |
Posted - 2007-06-22 : 10:53:55
|
Maybe I just haven't explain my issue very clearly...I need to return all entry no's for a particular day from the entry table, there may be 200 entries each day with varying no's. The query above specifies a set range from 655530 to 655537 which returns that range perfectly but what about the other 100 or so entry no's? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-22 : 11:00:21
|
can you post the more sample data and the expected result ? KH[spoiler]Time is always against us[/spoiler] |
|
|
dt293
Starting Member
8 Posts |
Posted - 2007-06-22 : 11:17:11
|
OK here is the top 10 from the Register table...No_ From Entry No_ To Entry No_ Creation Date----------- -------------- ------------ -----------------------537318 3466557 3466558 2007-06-22 00:00:00.000537319 3466559 3466560 2007-06-22 00:00:00.000537320 3466561 3466562 2007-06-22 00:00:00.000537321 3466563 3466577 2007-06-22 00:00:00.000537322 3466578 3466579 2007-06-22 00:00:00.000537323 3466580 3466592 2007-06-22 00:00:00.000537324 3466593 3466612 2007-06-22 00:00:00.000537325 3466613 3466613 2007-06-22 00:00:00.000537326 3466614 3466616 2007-06-22 00:00:00.000537327 3466617 3466619 2007-06-22 00:00:00.000I need to return each corresponding line from the entry table for every range on a particular day... for this example lets use the last range 3466617 to 3466619. This is what appears on the entry table for that range... Entry tableEntry No_ G_L Account No_ Document Type Document No_----------- -------------------- ------------- --------------------3466617 73320 2 PINV07_0097493466618 21422 2 PINV07_0097493466619 20010 2 PINV07_009749I would like to see every entry on a particluar day....Entry No_ G_L Account No_ Document Type Document No_ Creation Date----------- -------------------- ------------- ------------------------------------3466617 73320 2 PINV07_009749 2007-06-223466618 21422 2 PINV07_009749 2007-06-223466619 20010 2 PINV07_009749 2007-06-22Thanks again for you patience! |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-22 : 11:28:29
|
Is it what i posted earlier ?DECLARE @Register TABLE( [No] int, From_Entry_No int, To_Entry_No int, Creation_Date datetime)INSERT INTO @RegisterSELECT 537327, 3466617, 3466619, '2007-06-22'DECLARE @Entry TABLE( Entry_No int)INSERT INTO @EntrySELECT 3466616 UNION ALLSELECT 3466617 UNION ALLSELECT 3466618 UNION ALLSELECT 3466619 UNION ALLSELECT 3466620 SELECT e.Entry_No, r.Creation_DateFROM @Register r INNER JOIN @Entry e ON r.From_Entry_No <= e.Entry_No AND r.To_Entry_No >= e.Entry_No/*Entry_No Creation_Date ----------- ------------- 3466617 2007-06-22 3466618 2007-06-22 3466619 2007-06-22 */ KH[spoiler]Time is always against us[/spoiler] |
|
|
dt293
Starting Member
8 Posts |
Posted - 2007-06-22 : 11:59:31
|
I dont think so because the Entry No's are basically unknown, the code above assumes that you know what entry no's you need. I just want everything for the day.... |
|
|
|