Hi.
In SQL 2008 I have a table representing the beginning and ending date of each year:
I have another table with document numbers and dates:
I am wanting to update the #temp1.mindocno with the lowest temp2.docno between #temp1.begdate and #temp2.begdate
and update #temp2.maxdocno with the highest temp2.docno between #temp1.begdate and #temp2.begdate
So something like this:
#temp1
01-01-2011, 12-31-2011, 77777, 99999
01-01-2010, 12-31-2010, 44444, 66666
01-01-2009, 12-31-2009, 11111, 33333
Is there a way to do this? I don't really have a way to join the two tables so I'm not sure which way to go.
Thanks!
In SQL 2008 I have a table representing the beginning and ending date of each year:
Code:
create table #temp1 (begdate datetime, enddate datetime, mindocno int, maxdocno int)
insert into #temp1 (begdate, enddate) values (2011-01-01 00:00:00.000, 2011-12-31 23:59:59.997)
insert into #temp1 (begdate, enddate) values (2010-01-01 00:00:00.000, 2010-12-31 23:59:59.997)
insert into #temp1 (begdate, enddate) values (2009-01-01 00:00:00.000, 2009-12-31 23:59:59.997)
I have another table with document numbers and dates:
Code:
create table #temp2 (docno int, recordeddate datetime)
insert into #temp2 values (11111, '01-01-2009')
insert into #temp2 values (22222, '03-01-2009')
insert into #temp2 values (33333, '12-01-2009')
insert into #temp2 values (44444, '01-01-2010')
insert into #temp2 values (55555, '05-01-2010')
insert into #temp2 values (66666, '12-31-2010')
insert into #temp2 values (77777, '01-28-2011')
insert into #temp2 values (88888, '01-29-2011')
insert into #temp2 values (99999, '10-13-2011')
I am wanting to update the #temp1.mindocno with the lowest temp2.docno between #temp1.begdate and #temp2.begdate
and update #temp2.maxdocno with the highest temp2.docno between #temp1.begdate and #temp2.begdate
So something like this:
#temp1
01-01-2011, 12-31-2011, 77777, 99999
01-01-2010, 12-31-2010, 44444, 66666
01-01-2009, 12-31-2009, 11111, 33333
Is there a way to do this? I don't really have a way to join the two tables so I'm not sure which way to go.
Thanks!